[Fb-contrib-commit] SF.net SVN: fb-contrib: [570] trunk/fb-contrib
Brought to you by:
dbrosius
From: <dbr...@us...> - 2006-06-20 03:59:42
|
Revision: 570 Author: dbrosius Date: 2006-06-19 20:59:30 -0700 (Mon, 19 Jun 2006) ViewCVS: http://svn.sourceforge.net/fb-contrib/?rev=570&view=rev Log Message: ----------- Prepare for v2.8.0 Modified Paths: -------------- trunk/fb-contrib/build.xml trunk/fb-contrib/etc/findbugs.xml trunk/fb-contrib/htdocs/index.html trunk/fb-contrib/samples/ISB_Sample.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/InefficientStringBuffering.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseToArray.java Modified: trunk/fb-contrib/build.xml =================================================================== --- trunk/fb-contrib/build.xml 2006-06-20 03:26:29 UTC (rev 569) +++ trunk/fb-contrib/build.xml 2006-06-20 03:59:30 UTC (rev 570) @@ -19,7 +19,7 @@ <property name="javac.deprecation" value="on"/> <property name="javac.debug" value="on"/> - <property name="fb-contrib.version" value="2.7.0"/> + <property name="fb-contrib.version" value="2.8.0"/> <target name="clean" description="removes all generated collateral"> <delete dir="${classes.dir}"/> Modified: trunk/fb-contrib/etc/findbugs.xml =================================================================== --- trunk/fb-contrib/etc/findbugs.xml 2006-06-20 03:26:29 UTC (rev 569) +++ trunk/fb-contrib/etc/findbugs.xml 2006-06-20 03:59:30 UTC (rev 570) @@ -266,8 +266,8 @@ <BugPattern abbrev="S508C" type="S508C_NON_ACCESSIBLE_JCOMPONENT" category="CORRECTNESS" /> <BugPattern abbrev="S508C" type="S508C_SET_COMP_COLOR" category="CORRECTNESS" /> <BugPattern abbrev="UEC" type="UEC_USE_ENUM_COLLECTIONS" category="PERFORMANCE" /> - <BugPattern abbrev="SIL" type="SIL_SQL_IN_LOOP" category="PERFORMANCE" experimental="true" /> - <BugPattern abbrev="NMCS" type="NMCS_NEEDLESS_MEMBER_COLLECTION_SYNCHRONIZATION" category="PERFORMANCE" experimental="true" /> + <BugPattern abbrev="SIL" type="SIL_SQL_IN_LOOP" category="PERFORMANCE" /> + <BugPattern abbrev="NMCS" type="NMCS_NEEDLESS_MEMBER_COLLECTION_SYNCHRONIZATION" category="PERFORMANCE" /> <BugPattern abbrev="ITC" type="ITC_INHERITANCE_TYPE_CHECKING" category="STYLE" experimental="true" /> <BugPattern abbrev="SACM" type="SACM_STATIC_ARRAY_CREATED_IN_METHOD" category="PERFORMANCE" experimental="true" /> <BugPattern abbrev="RMC" type="RMC_REDUNDANT_METHOD_CALLS" category="PERFORMANCE" experimental="true" /> Modified: trunk/fb-contrib/htdocs/index.html =================================================================== --- trunk/fb-contrib/htdocs/index.html 2006-06-20 03:26:29 UTC (rev 569) +++ trunk/fb-contrib/htdocs/index.html 2006-06-20 03:59:30 UTC (rev 570) @@ -44,17 +44,24 @@ <a href="http://www.sourceforge.net/projects/fb-contrib">Project Page</a> <img src="vbar.gif" height="12"/> <a href="javadoc/index.html">JavaDoc</a> - - <hr/> - <img id="svn_image" src="flip2.gif" onClick="toggleBlock('svn', 'svn_image');" align="top"/> + + <hr/> + <img id="svn_image" src="flip1.gif" onClick="toggleBlock('svn', 'svn_image');" align="top"/> Detectors added in svn<br/> - Note: This version of fb-contrib requires FindBugs v1.0.0<br/> - <div id="svn" style="display:block;"> + <div id="svn" style="display:none;"> <ul> <li><b>[BSB] Bloated Synchronized Block</b><br/> Looks for methods that implement synchronized blocks that appear to contain some code at the beginning that does not need to be synchronized. Moving these lines out of the synchronized block should help multithreaded performance.</li> + </ul> + </div> + <hr/> + <img id="v2_8_0_image" src="flip2.gif" onClick="toggleBlock('v2_8_0', 'v2_8_0_image');" align="top"/> + Detectors added in v2.8.0<br/> + Note: This version of fb-contrib requires FindBugs v1.0.0<br/> + <div id="v2_8_0" style="display:block;"> + <ul> <li><b>[NMCS] Needless Member Collection Synchronization</b><br/> Looks for private collection members, either static or instance, that are only initialized in the clinit or init, but are synchronized. This is not necessary as the constructor or static @@ -72,7 +79,6 @@ cleaner to use mycollection.toArray(new type[mycollection.size()].</li> </ul> </div> - <hr/> <img id="v2_6_0_image" src="flip1.gif" onClick="toggleBlock('v2_6_0', 'v2_6_0_image');" align="top"/> Detectors added in v2.6.0<br/> Modified: trunk/fb-contrib/samples/ISB_Sample.java =================================================================== --- trunk/fb-contrib/samples/ISB_Sample.java 2006-06-20 03:26:29 UTC (rev 569) +++ trunk/fb-contrib/samples/ISB_Sample.java 2006-06-20 03:59:30 UTC (rev 570) @@ -51,6 +51,14 @@ return sb.toString(); } + public String testFPISB8(int x) + { + StringBuffer sb = new StringBuffer(); + sb.append(x); + sb.append("hello"); + return sb.toString(); + } + public String toString() { String a = System.getProperty("foo"); Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/InefficientStringBuffering.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/InefficientStringBuffering.java 2006-06-20 03:26:29 UTC (rev 569) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/InefficientStringBuffering.java 2006-06-20 03:59:30 UTC (rev 570) @@ -26,6 +26,7 @@ import edu.umd.cs.findbugs.BugReporter; import edu.umd.cs.findbugs.BytecodeScanningDetector; import edu.umd.cs.findbugs.OpcodeStack; +import edu.umd.cs.findbugs.ba.ClassContext; /** * looks for appending strings inside of calls to StringBuffer or StringBuilder append. @@ -33,7 +34,8 @@ public class InefficientStringBuffering extends BytecodeScanningDetector { private BugReporter bugReporter; - private OpcodeStack opStack; + private OpcodeStack stack; + private boolean sawLDCEmpty; /** * constructs a ISB detector given the reporter to report bugs on @@ -43,6 +45,19 @@ this.bugReporter = bugReporter; } + /** + * implements the visitor to create an clear the stack + * + * @param classContext the context object of the currently parsed class + */ + public void visitClassContext(ClassContext classContext) { + try { + stack = new OpcodeStack(); + super.visitClassContext(classContext); + } finally { + stack = null; + } + } /** * implements the visitor to create and clear the stack * @@ -51,16 +66,16 @@ @Override public void visitCode(final Code obj) { if (obj.getCode() != null) { - opStack = new OpcodeStack(); + stack.resetForMethodEntry(this); + sawLDCEmpty = false; super.visit(obj); - opStack = null; } } @Override public void sawOpcode(final int seen) { try { - opStack.mergeJumps(this); + stack.mergeJumps(this); if (seen == INVOKESPECIAL) { String calledClass = getClassConstantOperand(); @@ -78,40 +93,49 @@ } } } else if (seen == INVOKEVIRTUAL) { - String calledClass = getClassConstantOperand(); - if (("java/lang/StringBuffer".equals(calledClass) - || "java/lang/StringBuilder".equals(calledClass)) - && "append".equals(getNameConstantOperand()) - && getSigConstantOperand().startsWith("(Ljava/lang/String;)")) { - if (opStack.getStackDepth() > 0) { - OpcodeStack.Item itm = opStack.getStackItem(0); - Object cons = itm.getConstant(); - if ((cons instanceof String) && (itm.getRegisterNumber() < 0)) { - if (((String)cons).length() == 0) { - bugReporter.reportBug( - new BugInstance(this, "ISB_EMPTY_STRING_APPENDING", NORMAL_PRIORITY) - .addClass(this) - .addMethod(this) - .addSourceLine(this)); + if (sawLDCEmpty) { + String calledClass = getClassConstantOperand(); + if (("java/lang/StringBuffer".equals(calledClass) + || "java/lang/StringBuilder".equals(calledClass)) + && "append".equals(getNameConstantOperand()) + && getSigConstantOperand().startsWith("(Ljava/lang/String;)")) { + if (stack.getStackDepth() > 0) { + OpcodeStack.Item itm = stack.getStackItem(0); + Object cons = itm.getConstant(); + if ((cons instanceof String) && (itm.getRegisterNumber() < 0)) { + if (((String)cons).length() == 0) { + bugReporter.reportBug( + new BugInstance(this, "ISB_EMPTY_STRING_APPENDING", NORMAL_PRIORITY) + .addClass(this) + .addMethod(this) + .addSourceLine(this)); + } } } } } } else if (seen == GOTO) { - int depth = opStack.getStackDepth(); + int depth = stack.getStackDepth(); for (int i = 0; i < depth; i++) { - OpcodeStack.Item itm = opStack.getStackItem(i); + OpcodeStack.Item itm = stack.getStackItem(i); itm.setUserValue(Boolean.TRUE); } + } else if (seen == LDC) { + Constant c = getConstantRefOperand(); + if (c instanceof ConstantString) { + String s = ((ConstantString) c).getBytes(getConstantPool()); + if (s.length() == 0) + sawLDCEmpty = true; + } } } finally { - opStack.sawOpcode(this, seen); + stack.sawOpcode(this, seen); } } private OpcodeStack.Item getStringBufferItemAt(int depth) { - if (opStack.getStackDepth() > depth) { - OpcodeStack.Item itm = opStack.getStackItem(depth); + if (stack.getStackDepth() > depth) { + OpcodeStack.Item itm = stack.getStackItem(depth); String signature = itm.getSignature(); if ("Ljava/lang/StringBuffer;".equals(signature) || "Ljava/lang/StringBuilder;".equals(signature)) { Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseToArray.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseToArray.java 2006-06-20 03:26:29 UTC (rev 569) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseToArray.java 2006-06-20 03:59:30 UTC (rev 570) @@ -26,7 +26,6 @@ import org.apache.bcel.classfile.JavaClass; import com.mebigfatguy.fbcontrib.utils.Integer14; -import com.mebigfatguy.fbcontrib.utils.MapEntry; import com.mebigfatguy.fbcontrib.utils.RegisterUtils; import edu.umd.cs.findbugs.BugInstance; @@ -60,6 +59,11 @@ this.bugReporter = bugReporter; } + /** + * implements the visitor to create and clear the stack, and report missing class errors + * + * @param classContext the context object of the currently parsed class + */ public void visitClassContext(ClassContext classContext) { if (collectionClass == null) { if (ex != null) { @@ -77,6 +81,11 @@ } } + /** + * implements the visitor to reset the stack and uservalues + * + * @param obj the context object of the currently parsed code block + */ @Override public void visitCode(Code obj) { try { @@ -88,6 +97,11 @@ } } + /** + * implements the visitor to look for manually copying of collections to arrays + * + * @param seen the opcode of the currently parsed instruction + */ @Override public void sawOpcode(int seen) { int reg = -1; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |