[Fb-contrib-commit] SF.net SVN: fb-contrib: [566] trunk/fb-contrib/etc
Brought to you by:
dbrosius
From: <dbr...@us...> - 2006-06-19 05:28:47
|
Revision: 566 Author: dbrosius Date: 2006-06-18 22:28:38 -0700 (Sun, 18 Jun 2006) ViewCVS: http://svn.sourceforge.net/fb-contrib/?rev=566&view=rev Log Message: ----------- UTA starting to work for integer indexing, todo using iterators Modified Paths: -------------- trunk/fb-contrib/etc/findbugs.xml trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseToArray.java Modified: trunk/fb-contrib/etc/findbugs.xml =================================================================== --- trunk/fb-contrib/etc/findbugs.xml 2006-06-19 05:09:54 UTC (rev 565) +++ trunk/fb-contrib/etc/findbugs.xml 2006-06-19 05:28:38 UTC (rev 566) @@ -213,8 +213,7 @@ <Detector class="com.mebigfatguy.fbcontrib.detect.UseToArray" speed="fast" - reports="UTA_USE_TO_ARRAY" - hidden="true" /> + reports="UTA_USE_TO_ARRAY" /> <!-- BugPattern --> Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseToArray.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseToArray.java 2006-06-19 05:09:54 UTC (rev 565) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseToArray.java 2006-06-19 05:28:38 UTC (rev 566) @@ -29,6 +29,7 @@ import com.mebigfatguy.fbcontrib.utils.MapEntry; import com.mebigfatguy.fbcontrib.utils.RegisterUtils; +import edu.umd.cs.findbugs.BugInstance; import edu.umd.cs.findbugs.BugReporter; import edu.umd.cs.findbugs.BytecodeScanningDetector; import edu.umd.cs.findbugs.OpcodeStack; @@ -50,9 +51,6 @@ private BugReporter bugReporter; private OpcodeStack stack; private Map<Integer, Object> userValues; - /** map of pc of loop starts to map entry of index register to collection register */ - private Map<Integer, Map.Entry<Integer, Integer>> loopStarts; - /** * constructs a UTA detector given the reporter to report bugs on @@ -84,11 +82,9 @@ try { stack.resetForMethodEntry(this); userValues = new HashMap<Integer, Object>(); - loopStarts = new HashMap<Integer, Map.Entry<Integer, Integer>>(); super.visitCode(obj); } finally { userValues = null; - loopStarts = null; } } @@ -96,20 +92,30 @@ public void sawOpcode(int seen) { int reg = -1; Object uValue = null; - boolean sawSize = false; + boolean sawAlias = false; boolean sawLoad = false; boolean sawNewArray = false; try { if (seen == INVOKEINTERFACE) { - if ("size".equals(getNameConstantOperand()) && "()I".equals(getSigConstantOperand())) { + String methodName = getNameConstantOperand(); + String signature = getSigConstantOperand(); + if ("size".equals(methodName) && "()I".equals(signature)) { if (stack.getStackDepth() > 0) { OpcodeStack.Item itm = stack.getStackItem(0); reg = isLocalCollection(itm); if (reg >= 0) { - sawSize = true; + sawAlias = true; } } + } else if ("get".equals(methodName) && "(I)Ljava/lang/Object;".equals(signature)) { + if (stack.getStackDepth() > 1) { + OpcodeStack.Item itm = stack.getStackItem(1); + reg = isLocalCollection(itm); + if (reg >= 0) { + sawAlias = true; + } + } } } else if (((seen == ISTORE) || ((seen >= ISTORE_0) && (seen <= ISTORE_3))) || ((seen == ASTORE) || ((seen >= ASTORE_0) && (seen <= ASTORE_3)))) { @@ -131,23 +137,44 @@ if (stack.getStackDepth() > 1) { OpcodeStack.Item itm1 = stack.getStackItem(1); OpcodeStack.Item itm2 = stack.getStackItem(0); - Object const1 = itm1.getConstant(); reg = itm1.getRegisterNumber(); - if ((reg >= 0) && (const1 instanceof Integer)) { - if (0 == ((Integer) const1).intValue()) { - uValue = itm2.getUserValue(); - if (uValue != null) { - loopStarts.put(Integer14.valueOf(getPC()), new MapEntry<Integer, Integer>(Integer14.valueOf(reg), (Integer)uValue)); - } + if ((reg >= 0) && (itm1.couldBeZero())) { + uValue = itm2.getUserValue(); + if (uValue != null) { + userValues.put(Integer14.valueOf(reg), uValue); } } } + } else if ((seen >= IASTORE) && (seen <= SASTORE)) { + if (stack.getStackDepth() > 2) { + OpcodeStack.Item arItem = stack.getStackItem(2); + OpcodeStack.Item idxItem = stack.getStackItem(1); + OpcodeStack.Item valueItem = stack.getStackItem(0); + reg = isLocalCollection(arItem); + if ((reg >= 0) + && (idxItem.getUserValue() != null) + && (valueItem.getUserValue() != null)) { + bugReporter.reportBug(new BugInstance(this, "UTA_USE_TO_ARRAY", NORMAL_PRIORITY) + .addClass(this) + .addMethod(this) + .addSourceLine(this)); + } + } + } else if (seen == CHECKCAST) { + if (stack.getStackDepth() > 0) { + OpcodeStack.Item itm = stack.getStackItem(0); + uValue = itm.getUserValue(); + if (uValue instanceof Integer) { + reg = ((Integer)uValue).intValue(); + sawAlias = true; + } + } } } catch (ClassNotFoundException cnfe) { bugReporter.reportMissingClass(cnfe); } finally { stack.sawOpcode(this, seen); - if (sawSize) { + if (sawAlias) { if (stack.getStackDepth() > 0) { OpcodeStack.Item itm = stack.getStackItem(0); itm.setUserValue(Integer14.valueOf(reg)); @@ -188,7 +215,7 @@ return -1; JavaClass cls = item.getJavaClass(); - if (cls.implementationOf(collectionClass)) + if ((cls != null) && cls.implementationOf(collectionClass)) return reg; return -1; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |