[Fb-contrib-commit] fb-contrib/src/com/mebigfatguy/fbcontrib/detect ListIndexedIterating.java,1.5,1.
Brought to you by:
dbrosius
From: Dave B. <dbr...@us...> - 2005-10-14 03:31:08
|
Update of /cvsroot/fb-contrib/fb-contrib/src/com/mebigfatguy/fbcontrib/detect In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17403/src/com/mebigfatguy/fbcontrib/detect Modified Files: ListIndexedIterating.java Log Message: If a loop index is used to get values out of 2 or more collections, don't report it for LII Index: ListIndexedIterating.java =================================================================== RCS file: /cvsroot/fb-contrib/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ListIndexedIterating.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- ListIndexedIterating.java 12 Oct 2005 05:17:03 -0000 1.5 +++ ListIndexedIterating.java 14 Oct 2005 03:31:00 -0000 1.6 @@ -24,11 +24,10 @@ import org.apache.bcel.classfile.Code; -import sun.security.krb5.internal.crypto.n; - import edu.umd.cs.findbugs.BugInstance; import edu.umd.cs.findbugs.BugReporter; import edu.umd.cs.findbugs.BytecodeScanningDetector; +import edu.umd.cs.findbugs.FieldAnnotation; import edu.umd.cs.findbugs.OpcodeStack; import edu.umd.cs.findbugs.StatelessDetector; @@ -176,11 +175,14 @@ && "(I)Ljava/lang/Object;".equals(getSigConstantOperand()))) { it.remove(); } else { - if (stack.getStackDepth() > 0) { + if (stack.getStackDepth() > 1) { OpcodeStack.Item itm = stack.getStackItem(0); Integer initValue = (Integer)itm.getConstant(); if ((initValue == null) || (initValue.intValue() != 0)) it.remove(); + itm = stack.getStackItem(1); + if (fl.isSecondItem(itm)) + it.remove(); } fl.setLoopRegLoaded(false); } @@ -207,6 +209,7 @@ private int loopReg; private int loopState; private boolean loopRegLoaded; + private OpcodeStack.Item loopCollectionItem; public ForLoop( final int start, final int end, final int reg) { loopStart = start; @@ -214,6 +217,7 @@ loopReg = reg; loopState = LOOP_NOT_STARTED; loopRegLoaded = false; + loopCollectionItem = null; } public int getLoopStart() { @@ -243,5 +247,33 @@ public boolean getLoopRegLoaded() { return loopRegLoaded; } + + public boolean isSecondItem(OpcodeStack.Item itm) { + if (loopCollectionItem == null) { + loopCollectionItem = itm; + return false; + } + + int seenReg = loopCollectionItem.getRegisterNumber(); + if (seenReg >= 0) { + if (itm.getField() != null) + return true; + int newReg = itm.getRegisterNumber(); + if ((newReg >= 0) && (seenReg != newReg)) + return true; + } else { + FieldAnnotation seenField = loopCollectionItem.getField(); + if (seenField != null) { + if (itm.getRegisterNumber() >= 0) + return true; + FieldAnnotation newField = itm.getField(); + if ((newField != null) && (!newField.getFieldName().equals(seenField.getFieldName()))) + return true; + } + } + + loopCollectionItem = itm; + return false; + } } } |