Thread: [Fb-contrib-commit] SF.net SVN: fb-contrib: [414] trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/det
Brought to you by:
dbrosius
From: <dbr...@us...> - 2006-04-08 14:18:52
|
Revision: 414 Author: dbrosius Date: 2006-04-08 07:18:47 -0700 (Sat, 08 Apr 2006) ViewCVS: http://svn.sourceforge.net/fb-contrib/?rev=414&view=rev Log Message: ----------- prescreen for GOTO or GOTO_W opcodes Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ListIndexedIterating.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ListIndexedIterating.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ListIndexedIterating.java 2006-04-08 14:10:32 UTC (rev 413) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ListIndexedIterating.java 2006-04-08 14:18:47 UTC (rev 414) @@ -18,12 +18,17 @@ */ package com.mebigfatguy.fbcontrib.detect; +import java.util.BitSet; import java.util.HashSet; import java.util.Iterator; import java.util.Set; +import org.apache.bcel.Constants; import org.apache.bcel.classfile.Code; +import org.apache.bcel.classfile.Method; +import com.mebigfatguy.fbcontrib.utils.VersionTransition; + import edu.umd.cs.findbugs.BugInstance; import edu.umd.cs.findbugs.BugReporter; import edu.umd.cs.findbugs.BytecodeScanningDetector; @@ -77,24 +82,38 @@ } /** + * looks for methods that contain a GOTO or GOTO_W opcodes + * + * @param method the context object of the current method + * @return if the class uses synchronization + */ + public boolean prescreen(Method method) { + BitSet bytecodeSet = VersionTransition.getBytecodeSet(getClassContext(), method); + return (bytecodeSet != null) && (bytecodeSet.get(Constants.GOTO) || bytecodeSet.get(Constants.GOTO_W)); + } + + /** * overrides the visitor to reset the opcode stack * * @param obj the code object for the currently parsed Code */ @Override public void visitCode(final Code obj) { - sawListSize = false; - - stack.resetForMethodEntry(this); - state = SEEN_NOTHING; - stage = FIND_LOOP_STAGE; - super.visitCode(obj); - - if (sawListSize) { + Method m = getMethod(); + if (prescreen(m)) { + sawListSize = false; + stack.resetForMethodEntry(this); state = SEEN_NOTHING; - stage = FIND_BUG_STAGE; + stage = FIND_LOOP_STAGE; super.visitCode(obj); + + if (sawListSize) { + stack.resetForMethodEntry(this); + state = SEEN_NOTHING; + stage = FIND_BUG_STAGE; + super.visitCode(obj); + } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-04-18 02:55:01
|
Revision: 470 Author: dbrosius Date: 2006-04-17 19:54:55 -0700 (Mon, 17 Apr 2006) ViewCVS: http://svn.sourceforge.net/fb-contrib/?rev=470&view=rev Log Message: ----------- Manually cleanup memory now that StatelessDetector is removed. Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ListIndexedIterating.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ListIndexedIterating.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ListIndexedIterating.java 2006-04-18 02:43:21 UTC (rev 469) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ListIndexedIterating.java 2006-04-18 02:54:55 UTC (rev 470) @@ -32,14 +32,14 @@ import edu.umd.cs.findbugs.BytecodeScanningDetector; import edu.umd.cs.findbugs.FieldAnnotation; import edu.umd.cs.findbugs.OpcodeStack; -import edu.umd.cs.findbugs.StatelessDetector; +import edu.umd.cs.findbugs.ba.ClassContext; /** * looks for for loops that iterate over a java.util.List using an integer index, and get, * rather than using an Iterator. An iterator may perform better depending List implementation, * but more importantly will allow the code to be converted to other collections type. */ -public class ListIndexedIterating extends BytecodeScanningDetector implements StatelessDetector +public class ListIndexedIterating extends BytecodeScanningDetector { private static final int SEEN_NOTHING = 0; private static final int SEEN_IINC = 1; @@ -65,20 +65,22 @@ */ public ListIndexedIterating(final BugReporter bugReporter) { this.bugReporter = bugReporter; - stack = new OpcodeStack(); - possibleForLoops = new HashSet<ForLoop>(); } - + /** - * clone this detector so that it can be a StatelessDetector + * overrides the interface to create and clear the stack and loops tracker * - * @return a clone of this object + * @param classContext the context object for the currently parsed class */ @Override - public Object clone() throws CloneNotSupportedException { - return super.clone(); + public void visitClassContext(ClassContext classContext) { + stack = new OpcodeStack(); + possibleForLoops = new HashSet<ForLoop>(); + super.visitClassContext(classContext); + stack = null; + possibleForLoops = null; } - + /** * looks for methods that contain a GOTO or GOTO_W opcodes * This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-08-05 21:47:46
|
Revision: 586 Author: dbrosius Date: 2006-08-05 14:47:21 -0700 (Sat, 05 Aug 2006) ViewCVS: http://svn.sourceforge.net/fb-contrib/?rev=586&view=rev Log Message: ----------- prescreen for IINC as well. Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ListIndexedIterating.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ListIndexedIterating.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ListIndexedIterating.java 2006-08-05 21:31:40 UTC (rev 585) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ListIndexedIterating.java 2006-08-05 21:47:21 UTC (rev 586) @@ -92,7 +92,7 @@ */ public boolean prescreen(Method method) { BitSet bytecodeSet = getClassContext().getBytecodeSet(method); - return (bytecodeSet != null) && (bytecodeSet.get(Constants.GOTO) || bytecodeSet.get(Constants.GOTO_W)); + return (bytecodeSet != null) && (bytecodeSet.get(Constants.IINC)) && (bytecodeSet.get(Constants.GOTO) || bytecodeSet.get(Constants.GOTO_W)); } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-08-05 22:05:47
|
Revision: 587 Author: dbrosius Date: 2006-08-05 15:05:43 -0700 (Sat, 05 Aug 2006) ViewCVS: http://svn.sourceforge.net/fb-contrib/?rev=587&view=rev Log Message: ----------- make sure get is called on the loop index, before considering this loop an LII case. [ 1524122 ] LII thrown even if get(i) not called Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ListIndexedIterating.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ListIndexedIterating.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ListIndexedIterating.java 2006-08-05 21:47:21 UTC (rev 586) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ListIndexedIterating.java 2006-08-05 22:05:43 UTC (rev 587) @@ -47,6 +47,7 @@ private static final int LOOP_NOT_STARTED = 0; private static final int LOOP_INDEX_LOADED_FOR_TEST = 1; private static final int LOOP_IN_BODY = 2; + private static final int LOOP_IN_BODY_WITH_GET = 3; private static final int FIND_LOOP_STAGE = 0; private static final int FIND_BUG_STAGE = 1; @@ -220,7 +221,8 @@ break; case LOOP_IN_BODY: - if (getPC() == fl.getLoopEnd()) { + case LOOP_IN_BODY_WITH_GET: + if ((getPC() == fl.getLoopEnd()) && (fl.getLoopState() == LOOP_IN_BODY_WITH_GET)) { bugReporter.reportBug(new BugInstance( this, "LII_LIST_INDEXED_ITERATING", NORMAL_PRIORITY ) .addClass(this) .addMethod(this) @@ -236,12 +238,14 @@ if (loopReg == fl.getLoopReg()) fl.setLoopRegLoaded(true); } else if (fl.getLoopRegLoaded()) { - if (!((seen == INVOKEINTERFACE) - && "java/util/List".equals(getClassConstantOperand()) - && "get".equals(getNameConstantOperand()) - && "(I)Ljava/lang/Object;".equals(getSigConstantOperand()))) { + boolean sawGet = ((seen == INVOKEINTERFACE) + && "java/util/List".equals(getClassConstantOperand()) + && "get".equals(getNameConstantOperand()) + && "(I)Ljava/lang/Object;".equals(getSigConstantOperand())); + if (!sawGet) { it.remove(); } else { + fl.setLoopState(LOOP_IN_BODY_WITH_GET); if (stack.getStackDepth() > 1) { OpcodeStack.Item itm = stack.getStackItem(0); Integer initValue = (Integer)itm.getConstant(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-08-05 22:16:29
|
Revision: 588 Author: dbrosius Date: 2006-08-05 15:16:24 -0700 (Sat, 05 Aug 2006) ViewCVS: http://svn.sourceforge.net/fb-contrib/?rev=588&view=rev Log Message: ----------- fix LII due to changes in OpcodeStack, not setting a variable constant to 0 when the assignment is a for loop. Use couldBeZero() instead. Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ListIndexedIterating.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ListIndexedIterating.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ListIndexedIterating.java 2006-08-05 22:05:43 UTC (rev 587) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ListIndexedIterating.java 2006-08-05 22:16:24 UTC (rev 588) @@ -248,8 +248,7 @@ fl.setLoopState(LOOP_IN_BODY_WITH_GET); if (stack.getStackDepth() > 1) { OpcodeStack.Item itm = stack.getStackItem(0); - Integer initValue = (Integer)itm.getConstant(); - if ((initValue == null) || (initValue.intValue() != 0)) + if (!itm.couldBeZero()) it.remove(); else { itm = stack.getStackItem(1); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |