Thread: [Fb-contrib-commit] SF.net SVN: fb-contrib: [468] trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/det
Brought to you by:
dbrosius
From: <dbr...@us...> - 2006-04-17 15:52:18
|
Revision: 468 Author: dbrosius Date: 2006-04-17 08:52:11 -0700 (Mon, 17 Apr 2006) ViewCVS: http://svn.sourceforge.net/fb-contrib/?rev=468&view=rev Log Message: ----------- Manually cleanup memory now that StatelessDetector is removed. Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/InefficientStringBuffering.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/InefficientStringBuffering.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/InefficientStringBuffering.java 2006-04-17 15:50:21 UTC (rev 467) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/InefficientStringBuffering.java 2006-04-17 15:52:11 UTC (rev 468) @@ -24,13 +24,12 @@ import edu.umd.cs.findbugs.BugReporter; import edu.umd.cs.findbugs.BytecodeScanningDetector; import edu.umd.cs.findbugs.OpcodeStack; -import edu.umd.cs.findbugs.StatelessDetector; import edu.umd.cs.findbugs.OpcodeStack.Item; /** * looks for appending strings inside of calls to StringBuffer or StringBuilder append. */ -public class InefficientStringBuffering extends BytecodeScanningDetector implements StatelessDetector +public class InefficientStringBuffering extends BytecodeScanningDetector { private BugReporter bugReporter; private OpcodeStack opStack; @@ -41,24 +40,19 @@ */ public InefficientStringBuffering(final BugReporter bugReporter) { this.bugReporter = bugReporter; - opStack = new OpcodeStack(); } - /** - * clone this detector so that it can be a StatelessDetector - * - * @return a clone of this object - */ + /** + * implements the visitor to create and clear the stack + * + * @param obj the context object of the currently parsed code block + */ @Override - public Object clone() throws CloneNotSupportedException { - return super.clone(); - } - - @Override - public void visit(final Code c) { - if (c.getCode() != null) { - opStack.resetForMethodEntry(this); - super.visit(c); + public void visitCode(final Code obj) { + if (obj.getCode() != null) { + opStack = new OpcodeStack(); + super.visit(obj); + opStack = null; } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-04-27 03:27:15
|
Revision: 504 Author: dbrosius Date: 2006-04-26 20:27:09 -0700 (Wed, 26 Apr 2006) ViewCVS: http://svn.sourceforge.net/fb-contrib/?rev=504&view=rev Log Message: ----------- don't report ISB's caused by trinaries inserting a second StringBuffer inside a parent string buffer Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/InefficientStringBuffering.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/InefficientStringBuffering.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/InefficientStringBuffering.java 2006-04-25 20:52:37 UTC (rev 503) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/InefficientStringBuffering.java 2006-04-27 03:27:09 UTC (rev 504) @@ -24,7 +24,6 @@ import edu.umd.cs.findbugs.BugReporter; import edu.umd.cs.findbugs.BytecodeScanningDetector; import edu.umd.cs.findbugs.OpcodeStack; -import edu.umd.cs.findbugs.OpcodeStack.Item; /** * looks for appending strings inside of calls to StringBuffer or StringBuilder append. @@ -67,22 +66,35 @@ || "java/lang/StringBuilder".equals(calledClass)) && "<init>".equals(getNameConstantOperand()) && "()V".equals(getSigConstantOperand())) { - if (opStack.getStackDepth() > 2) { - Item itm = opStack.getStackItem(2); - String signature = itm.getSignature(); - if ("Ljava/lang/StringBuffer;".equals(signature) - || "Ljava/lang/StringBuilder;".equals(signature)) { - bugReporter.reportBug( - new BugInstance(this, "ISB_INEFFICIENT_STRING_BUFFERING", "toString".equals(getMethodName()) ? LOW_PRIORITY : NORMAL_PRIORITY) - .addClass(this) - .addMethod(this) - .addSourceLine(this)); - } + OpcodeStack.Item itm = getStringBufferItemAt(2); + if ((itm != null) && (itm.getUserValue() == null)) { + bugReporter.reportBug( + new BugInstance(this, "ISB_INEFFICIENT_STRING_BUFFERING", "toString".equals(getMethodName()) ? LOW_PRIORITY : NORMAL_PRIORITY) + .addClass(this) + .addMethod(this) + .addSourceLine(this)); } } + } else if (seen == GOTO) { + OpcodeStack.Item itm = getStringBufferItemAt(1); + if (itm != null) + itm.setUserValue(Boolean.TRUE); } } finally { opStack.sawOpcode(this, seen); } } + + private OpcodeStack.Item getStringBufferItemAt(int depth) { + if (opStack.getStackDepth() > depth) { + OpcodeStack.Item itm = opStack.getStackItem(depth); + String signature = itm.getSignature(); + if ("Ljava/lang/StringBuffer;".equals(signature) + || "Ljava/lang/StringBuilder;".equals(signature)) { + return itm; + } + } + + return null; + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-06-08 17:53:16
|
Revision: 561 Author: dbrosius Date: 2006-06-08 10:52:39 -0700 (Thu, 08 Jun 2006) ViewCVS: http://svn.sourceforge.net/fb-contrib/?rev=561&view=rev Log Message: ----------- try to suppress more fp's due to trinaries around string buffering Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/InefficientStringBuffering.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/InefficientStringBuffering.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/InefficientStringBuffering.java 2006-06-08 02:47:32 UTC (rev 560) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/InefficientStringBuffering.java 2006-06-08 17:52:39 UTC (rev 561) @@ -76,9 +76,11 @@ } } } else if (seen == GOTO) { - OpcodeStack.Item itm = getStringBufferItemAt(1); - if (itm != null) + int depth = opStack.getStackDepth(); + for (int i = 0; i < depth; i++) { + OpcodeStack.Item itm = opStack.getStackItem(i); itm.setUserValue(Boolean.TRUE); + } } } finally { opStack.sawOpcode(this, seen); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |