[Fb-contrib-commit] SF.net SVN: fb-contrib: [694] trunk/fb-contrib
Brought to you by:
dbrosius
From: <dbr...@us...> - 2006-11-20 01:31:31
|
Revision: 694 http://svn.sourceforge.net/fb-contrib/?rev=694&view=rev Author: dbrosius Date: 2006-11-19 17:31:22 -0800 (Sun, 19 Nov 2006) Log Message: ----------- add assignment stutter checking 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 05:52:18 UTC (rev 693) +++ trunk/fb-contrib/etc/findbugs.xml 2006-11-20 01:31:22 UTC (rev 694) @@ -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"/> + reports="SPP_NEGATIVE_BITSET_ITEM,SPP_INTERN_ON_CONSTANT,SPP_NO_CHAR_SB_CTOR,SPP_USE_MATH_CONSTANT,SPP_STUTTERED_ASSIGNMENT"/> <!-- BugPattern --> @@ -327,5 +327,6 @@ <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" /> <BugPattern abbrev="SPP" type="SPP_USE_MATH_CONSTANT" category="CORRECTNESS" experimental="true" /> + <BugPattern abbrev="SPP" type="SPP_STUTTERED_ASSIGNMENT" 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 05:52:18 UTC (rev 693) +++ trunk/fb-contrib/etc/messages.xml 2006-11-20 01:31:22 UTC (rev 694) @@ -1562,6 +1562,18 @@ </Details> </BugPattern> + <BugPattern type="SPP_STUTTERED_ASSIGNMENT"> + <ShortDescription>Method assigns a value to a local twice in a row</ShortDescription> + <LongDescription>Method {1} assigns a value to a local twice in a row</LongDescription> + <Details> + <![CDATA[ + <p>This method assigns a value twice in a row in a stuttered way such as + <code>a = a = 5;</code> This is most probably a cut and paste error where the duplicate + assignment can be removed.</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 05:52:18 UTC (rev 693) +++ trunk/fb-contrib/samples/SPP_Sample.java 2006-11-20 01:31:22 UTC (rev 694) @@ -26,4 +26,9 @@ { return pi * radius * radius; } + + public void testStutter(String s) + { + String a = a = s; + } } Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java 2006-11-19 05:52:18 UTC (rev 693) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java 2006-11-20 01:31:22 UTC (rev 694) @@ -21,6 +21,8 @@ import org.apache.bcel.classfile.Code; import org.apache.bcel.classfile.ConstantDouble; +import com.mebigfatguy.fbcontrib.utils.RegisterUtils; + import edu.umd.cs.findbugs.BugInstance; import edu.umd.cs.findbugs.BugReporter; import edu.umd.cs.findbugs.BytecodeScanningDetector; @@ -35,6 +37,7 @@ private BugReporter bugReporter; private OpcodeStack stack; private int lastOpcode; + private int lastReg; /** * constructs a SPP detector given the reporter to report bugs on @@ -61,6 +64,7 @@ public void visitCode(Code obj) { stack.resetForMethodEntry(this); lastOpcode = -1; + lastReg = -1; super.visitCode(obj); } @@ -70,6 +74,7 @@ * @param seen the opcode of the currently parsed instruction */ public void sawOpcode(int seen) { + int reg = -1; try { stack.mergeJumps(this); @@ -88,6 +93,16 @@ .addSourceLine(this)); } } + } else if (((seen >= ASTORE_0) && (seen < ASTORE_3)) || (seen == ASTORE)) { + reg = RegisterUtils.getAStoreReg(this, seen); + if (seen == lastOpcode) { + if (reg == lastReg) { + bugReporter.reportBug(new BugInstance(this, "SPP_STUTTERED_ASSIGNMENT", NORMAL_PRIORITY) + .addClass(this) + .addMethod(this) + .addSourceLine(this)); + } + } } else if (seen == INVOKEVIRTUAL) { String className = getClassConstantOperand(); String methodName = getNameConstantOperand(); @@ -157,6 +172,7 @@ } finally { stack.sawOpcode(this, seen); lastOpcode = seen; + lastReg = reg; } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |