[Fb-contrib-commit] SF.net SVN: fb-contrib: [587] trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/de
Brought to you by:
dbrosius
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. |