[Fb-contrib-commit] SF.net SVN: fb-contrib: [686] trunk/fb-contrib
Brought to you by:
dbrosius
From: <dbr...@us...> - 2006-11-19 03:38:31
|
Revision: 686 http://svn.sourceforge.net/fb-contrib/?rev=686&view=rev Author: dbrosius Date: 2006-11-18 19:38:28 -0800 (Sat, 18 Nov 2006) Log Message: ----------- add Constant string interning 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:16:44 UTC (rev 685) +++ trunk/fb-contrib/etc/findbugs.xml 2006-11-19 03:38:28 UTC (rev 686) @@ -256,7 +256,7 @@ <Detector class="com.mebigfatguy.fbcontrib.detect.SillynessPotPourri" speed="fast" - reports="SPP_NEGATIVE_BITSET_ITEM"/> + reports="SPP_NEGATIVE_BITSET_ITEM,SPP_INTERN_ON_CONSTANT"/> <!-- BugPattern --> @@ -324,5 +324,6 @@ <BugPattern abbrev="PIS" type="PIS_POSSIBLE_INCOMPLETE_SERIALIZATION" category="CORRECTNESS" /> <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" /> </FindbugsPlugin> \ No newline at end of file Modified: trunk/fb-contrib/etc/messages.xml =================================================================== --- trunk/fb-contrib/etc/messages.xml 2006-11-19 03:16:44 UTC (rev 685) +++ trunk/fb-contrib/etc/messages.xml 2006-11-19 03:38:28 UTC (rev 686) @@ -1527,6 +1527,17 @@ </Details> </BugPattern> + <BugPattern type="SPP_INTERN_ON_CONSTANT"> + <ShortDescription>Method calls intern on a string constant</ShortDescription> + <LongDescription>Method {1} calls intern on a string constant</LongDescription> + <Details> + <![CDATA[ + <p>This method calls intern on a constant string. As constant strings are already interned, this call + is superfluous</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:16:44 UTC (rev 685) +++ trunk/fb-contrib/samples/SPP_Sample.java 2006-11-19 03:38:28 UTC (rev 686) @@ -2,9 +2,15 @@ public class SPP_Sample { + public void testSPPBitSet(BitSet b) { b.set(-1); } + + public String testSPPIntern() + { + return "FOO".intern(); //and yes i've seen this! + } } 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:16:44 UTC (rev 685) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java 2006-11-19 03:38:28 UTC (rev 686) @@ -33,6 +33,7 @@ { private BugReporter bugReporter; private OpcodeStack stack; + /** * constructs a SPP detector given the reporter to report bugs on * @param bugReporter the sync of bug reports @@ -71,8 +72,8 @@ if (seen == INVOKEVIRTUAL) { String className = getClassConstantOperand(); + String methodName = getNameConstantOperand(); if ("java/util/BitSet".equals(className)) { - String methodName = getNameConstantOperand(); if ("clear".equals(methodName) || "flip".equals(methodName) || "get".equals(methodName) @@ -90,6 +91,18 @@ } } } + } else if ("java/lang/String".equals(className)) { + if ("intern".equals(methodName)) { + if (stack.getStackDepth() > 0) { + OpcodeStack.Item item = stack.getStackItem(0); + if (item.getConstant() != null) { + bugReporter.reportBug(new BugInstance(this, "SPP_INTERN_ON_CONSTANT", NORMAL_PRIORITY) + .addClass(this) + .addMethod(this) + .addSourceLine(this)); + } + } + } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |