[Fb-contrib-commit] SF.net SVN: fb-contrib: [687] trunk/fb-contrib
Brought to you by:
dbrosius
From: <dbr...@us...> - 2006-11-19 03:56:32
|
Revision: 687 http://svn.sourceforge.net/fb-contrib/?rev=687&view=rev Author: dbrosius Date: 2006-11-18 19:56:31 -0800 (Sat, 18 Nov 2006) Log Message: ----------- add StringBuffer(char) to SPP 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-11-19 03:38:28 UTC (rev 686) +++ trunk/fb-contrib/etc/findbugs.xml 2006-11-19 03:56:31 UTC (rev 687) @@ -256,7 +256,7 @@ <Detector class="com.mebigfatguy.fbcontrib.detect.SillynessPotPourri" speed="fast" - reports="SPP_NEGATIVE_BITSET_ITEM,SPP_INTERN_ON_CONSTANT"/> + reports="SPP_NEGATIVE_BITSET_ITEM,SPP_INTERN_ON_CONSTANT,SPP_NO_CHAR_SB_CTOR"/> <!-- BugPattern --> @@ -325,5 +325,6 @@ <BugPattern abbrev="SCRV" type="SC_SUSPICIOUS_COMPARATOR_RETURN_VALUES" category="CORRECTNESS" experimental="true" /> <BugPattern abbrev="SPP" type="SPP_NEGATIVE_BITSET_ITEM" category="CORRECTNESS" experimental="true" /> <BugPattern abbrev="SPP" type="SPP_INTERN_ON_CONSTANT" category="CORRECTNESS" experimental="true" /> + <BugPattern abbrev="SPP" type="SPP_NO_CHAR_SB_CTOR" category="CORRECTNESS" experimental="true" /> </FindbugsPlugin> \ No newline at end of file Modified: trunk/fb-contrib/etc/messages.xml =================================================================== --- trunk/fb-contrib/etc/messages.xml 2006-11-19 03:38:28 UTC (rev 686) +++ trunk/fb-contrib/etc/messages.xml 2006-11-19 03:56:31 UTC (rev 687) @@ -1538,6 +1538,19 @@ </Details> </BugPattern> + <BugPattern type="SPP_NO_CHAR_SB_CTOR"> + <ShortDescription>Method passes character to StringBuffer or StringBuilder integer constructor</ShortDescription> + <LongDescription>Method {1} passes character to StringBuffer or StringBuilder integer cosntructor</LongDescription> + <Details> + <![CDATA[ + <p>This method constructs a StringBuffer or a StringBuilder using the constructor that takes an integer, but + passes a character instead. It is probable that the author assumed that character would be appended to the + StringBuffer/Builder, but instead the integer value of the character is used as an initial size for the buffer. + </p> + ]]> + </Details> + </BugPattern> + <!-- BugCode --> <BugCode abbrev="ISB">Inefficient String Buffering</BugCode> Modified: trunk/fb-contrib/samples/SPP_Sample.java =================================================================== --- trunk/fb-contrib/samples/SPP_Sample.java 2006-11-19 03:38:28 UTC (rev 686) +++ trunk/fb-contrib/samples/SPP_Sample.java 2006-11-19 03:56:31 UTC (rev 687) @@ -12,5 +12,11 @@ { return "FOO".intern(); //and yes i've seen this! } - + + public String testSBWithChars() + { + StringBuffer sb = new StringBuffer('v'); + sb.append("ictory"); + return sb.toString(); + } } Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java 2006-11-19 03:38:28 UTC (rev 686) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java 2006-11-19 03:56:31 UTC (rev 687) @@ -33,6 +33,7 @@ { private BugReporter bugReporter; private OpcodeStack stack; + private int lastOpcode; /** * constructs a SPP detector given the reporter to report bugs on @@ -58,6 +59,7 @@ */ public void visitCode(Code obj) { stack.resetForMethodEntry(this); + lastOpcode = -1; super.visitCode(obj); } @@ -104,10 +106,28 @@ } } } + } else if (seen == INVOKESPECIAL) { + String className = getClassConstantOperand(); + if ("java/lang/StringBuffer".equals(className) + || "java/lang/StringBuilder".equals(className)) { + String methodName = getNameConstantOperand(); + if ("<init>".equals(methodName)) { + String signature = getSigConstantOperand(); + if ("(I)V".equals(signature)) { + if (lastOpcode == BIPUSH) { + bugReporter.reportBug(new BugInstance(this, "SPP_NO_CHAR_SB_CTOR", NORMAL_PRIORITY) + .addClass(this) + .addMethod(this) + .addSourceLine(this)); + } + } + } + } } } finally { stack.sawOpcode(this, seen); + lastOpcode = seen; } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |