[Fb-contrib-commit] SF.net SVN: fb-contrib: [727] trunk/fb-contrib
Brought to you by:
dbrosius
From: <dbr...@us...> - 2006-12-13 16:47:19
|
Revision: 727 http://svn.sourceforge.net/fb-contrib/?rev=727&view=rev Author: dbrosius Date: 2006-12-13 08:46:58 -0800 (Wed, 13 Dec 2006) Log Message: ----------- add check for StringBuffer("") Modified Paths: -------------- trunk/fb-contrib/etc/findbugs.xml trunk/fb-contrib/etc/messages.xml trunk/fb-contrib/samples/SPP_Sample.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java Modified: trunk/fb-contrib/etc/findbugs.xml =================================================================== --- trunk/fb-contrib/etc/findbugs.xml 2006-12-13 05:37:35 UTC (rev 726) +++ trunk/fb-contrib/etc/findbugs.xml 2006-12-13 16:46:58 UTC (rev 727) @@ -256,7 +256,7 @@ <Detector class="com.mebigfatguy.fbcontrib.detect.SillynessPotPourri" speed="fast" - reports="SPP_NEGATIVE_BITSET_ITEM,SPP_INTERN_ON_CONSTANT,SPP_NO_CHAR_SB_CTOR,SPP_USE_MATH_CONSTANT,SPP_STUTTERED_ASSIGNMENT,SPP_USE_ISNAN,SPP_USE_BIGDECIMAL_STRING_CTOR"/> + reports="SPP_NEGATIVE_BITSET_ITEM,SPP_INTERN_ON_CONSTANT,SPP_NO_CHAR_SB_CTOR,SPP_USE_MATH_CONSTANT,SPP_STUTTERED_ASSIGNMENT,SPP_USE_ISNAN,SPP_USE_BIGDECIMAL_STRING_CTOR,SPP_STRINGBUFFER_WITH_EMPTY_STRING"/> <Detector class="com.mebigfatguy.fbcontrib.detect.BloatedAssignmentScope" speed="fast" @@ -338,6 +338,7 @@ <BugPattern abbrev="SPP" type="SPP_STUTTERED_ASSIGNMENT" category="CORRECTNESS" experimental="true" /> <BugPattern abbrev="SPP" type="SPP_USE_ISNAN" category="CORRECTNESS" experimental="true" /> <BugPattern abbrev="SPP" type="SPP_USE_BIGDECIMAL_STRING_CTOR" category="CORRECTNESS" experimental="true" /> + <BugPattern abbrev="SPP" type="SPP_STRINGBUFFER_WITH_EMPTY_STRING" category="PERFORMANCE" experimental="true" /> <BugPattern abbrev="BAS" type="BAS_BLOATED_ASSIGNMENT_SCOPE" category="PERFORMANCE" experimental="true" /> <BugPattern abbrev="SCII" type="SCII_SPOILED_CHILD_INTERFACE_IMPLEMENTATOR" category="STYLE" experimental="true" /> </FindbugsPlugin> \ No newline at end of file Modified: trunk/fb-contrib/etc/messages.xml =================================================================== --- trunk/fb-contrib/etc/messages.xml 2006-12-13 05:37:35 UTC (rev 726) +++ trunk/fb-contrib/etc/messages.xml 2006-12-13 16:46:58 UTC (rev 727) @@ -1616,6 +1616,18 @@ </Details> </BugPattern> + <BugPattern type="SPP_STRINGBUFFER_WITH_EMPTY_STRING"> + <ShortDescription>Method passes empty string to StringBuffer of StringBuilder constructor</ShortDescription> + <LongDescription>Method {1} passes empty string to StringBuffer of StringBuilder constructor</LongDescription> + <Details> + <![CDATA[ + <p>This method calls the StringBuffer of StringBuilder constructor passing in a constant empty string (""). + This is the same as calling the default constructor, but makes the code work harder. Consider passing in a + default size instead. + ]]> + </Details> + </BugPattern> + <BugPattern type="BAS_BLOATED_ASSIGNMENT_SCOPE"> <ShortDescription>Method assigns a variable in a larger scope then is needed</ShortDescription> <LongDescription>Method {1} assigns a variable in a larger scope then is needed</LongDescription> Modified: trunk/fb-contrib/samples/SPP_Sample.java =================================================================== --- trunk/fb-contrib/samples/SPP_Sample.java 2006-12-13 05:37:35 UTC (rev 726) +++ trunk/fb-contrib/samples/SPP_Sample.java 2006-12-13 16:46:58 UTC (rev 727) @@ -49,4 +49,9 @@ { BigDecimal d = new BigDecimal(2.1); } + + public void testEmptySB() + { + StringBuffer sb = new StringBuffer(""); + } } Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java 2006-12-13 05:37:35 UTC (rev 726) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java 2006-12-13 16:46:58 UTC (rev 727) @@ -164,7 +164,7 @@ } } } - } + } } else if (seen == INVOKESPECIAL) { String className = getClassConstantOperand(); if ("java/lang/StringBuffer".equals(className) @@ -192,7 +192,16 @@ } } } - } + } else if ("(Ljava/lang/String;)V".equals(signature)) { + OpcodeStack.Item item = stack.getStackItem(0); + String con = (String)item.getConstant(); + if ("".equals(con)) { + bugReporter.reportBug(new BugInstance(this, "SPP_STRINGBUFFER_WITH_EMPTY_STRING", NORMAL_PRIORITY) + .addClass(this) + .addMethod(this) + .addSourceLine(this)); + } + } } } else if ("java/math/BigDecimal".equals(className)) { if (stack.getStackDepth() > 0) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |