Thread: [Fb-contrib-commit] SF.net SVN: fb-contrib: [738] trunk/fb-contrib/src/com/mebigfatguy/ fbcontrib/
Brought to you by:
dbrosius
|
From: <dbr...@us...> - 2006-12-19 07:41:38
|
Revision: 738
http://svn.sourceforge.net/fb-contrib/?rev=738&view=rev
Author: dbrosius
Date: 2006-12-18 23:41:37 -0800 (Mon, 18 Dec 2006)
Log Message:
-----------
more fleshing out
Modified Paths:
--------------
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java 2006-12-19 06:57:27 UTC (rev 737)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java 2006-12-19 07:41:37 UTC (rev 738)
@@ -32,6 +32,7 @@
import com.mebigfatguy.fbcontrib.utils.Integer14;
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;
@@ -61,7 +62,8 @@
private BugReporter bugReporter;
private OpcodeStack stack;
private List<Set<Comparable>> collectionGroups;
- private Map<Integer, Integer> iteratorToGroup;
+ private Map<Integer, Integer> groupToIterator;
+ private Map<Integer, Loop> loops;
/**
* constructs a DWI detector given the reporter to report bugs on
@@ -72,7 +74,7 @@
}
/**
- * implements the visitor to setup the opcode stack, and collectionGroups
+ * implements the visitor to setup the opcode stack, collectionGroups, groupToIterator and loops
*
* @param classContext the context object of the currently parsed class
*/
@@ -83,24 +85,27 @@
try {
stack = new OpcodeStack();
collectionGroups = new ArrayList<Set<Comparable>>();
- iteratorToGroup = new HashMap<Integer, Integer>();
+ groupToIterator = new HashMap<Integer, Integer>();
+ loops = new HashMap<Integer, Loop>();
super.visitClassContext(classContext);
} finally {
stack = null;
collectionGroups = null;
- iteratorToGroup = null;
+ groupToIterator = null;
+ loops = null;
}
}
/**
- * implements the visitor to reset the stack and collectionGroups
+ * implements the visitor to reset the stack, collectionGroups, groupToIterator and loops
*
* @param obj the context object of the currently parsed code block
*/
public void visitCode(Code obj) {
stack.resetForMethodEntry(this);
collectionGroups.clear();
- iteratorToGroup.clear();
+ groupToIterator.clear();
+ loops.clear();
super.visitCode(obj);
}
@@ -116,25 +121,48 @@
if (seen == INVOKEINTERFACE)
{
String className = getClassConstantOperand();
+ String methodName = getNameConstantOperand();
+ String signature = getSigConstantOperand();
+ String methodInfo = methodName + signature;
+
if (isCollection(className)) {
- String methodName = getNameConstantOperand();
- String signature = getSigConstantOperand();
- String methodInfo = methodName + signature;
if (collectionMethods.contains(methodInfo)) {
if (stack.getStackDepth() > 0) {
OpcodeStack.Item itm = stack.getStackItem(0);
- groupId = findCollectionGroup(itm);
+ groupId = findCollectionGroup(itm, true);
}
} else if ("iterator()Ljava/util/Iterator;".equals(methodInfo)) {
if (stack.getStackDepth() > 0) {
OpcodeStack.Item itm = stack.getStackItem(0);
- groupId = findCollectionGroup(itm);
-
+ groupId = findCollectionGroup(itm, true);
}
} else if ("remove(Ljava/lang/Object;)Z".equals(methodInfo)) {
-
+ if (stack.getStackDepth() > 0) {
+ OpcodeStack.Item itm = stack.getStackItem(0);
+ int id = findCollectionGroup(itm, true);
+ if (id >= 0) {
+ Integer it = groupToIterator.get(id);
+ Loop loop = loops.get(it);
+ if (loop != null) {
+ int pc = getPC();
+ if (loop.hasPC(pc)) {
+ bugReporter.reportBug(new BugInstance(this, "DWI_DELETING_WHILE_ITERATING", NORMAL_PRIORITY)
+ .addClass(this)
+ .addMethod(this)
+ .addSourceLine(this));
+ }
+ }
+ }
+ }
}
+ } else if ("java/util/Iterator".equals(className) && "hasNext()Z".equals(methodInfo)) {
+ if (stack.getStackDepth() > 0) {
+ OpcodeStack.Item itm = stack.getStackItem(0);
+ Integer id = (Integer)itm.getUserValue();
+ if (id != null)
+ groupId = id.intValue();
+ }
}
} else if ((seen == ASTORE) || ((seen >= ASTORE_0) && (seen <= ASTORE_3))) {
if (stack.getStackDepth() > 0) {
@@ -145,19 +173,34 @@
try {
if (itm.getJavaClass().implementationOf(iteratorClass)) {
- iteratorToGroup.put(Integer14.valueOf(reg), id);
- } else {
- Set<Comparable> group = collectionGroups.get(id);
- if (group != null) {
- group.add(Integer14.valueOf(reg));
- }
+ groupToIterator.put(id, Integer14.valueOf(reg));
}
+
+ Set<Comparable> group = collectionGroups.get(id);
+ if (group != null) {
+ group.add(Integer14.valueOf(reg));
+ }
} catch (ClassNotFoundException cnfe) {
bugReporter.reportMissingClass(cnfe);
}
}
}
-
+ } else if ((seen == ALOAD) || ((seen >= ALOAD_0) && (seen <= ALOAD_3))) {
+ int reg = RegisterUtils.getALoadReg(this, seen);
+ OpcodeStack.Item itm = new OpcodeStack.Item(new OpcodeStack.Item(), reg);
+ groupId = findCollectionGroup(itm, false);
+ } else if (seen == IFEQ) {
+ if (stack.getStackDepth() > 0) {
+ OpcodeStack.Item itm = stack.getStackItem(0);
+ Integer id = (Integer)itm.getUserValue();
+ if (id != null) {
+ int target = getBranchTarget();
+ int gotoAddr = target - 3;
+ if (getCode().getCode()[gotoAddr] == GOTO) {
+ loops.put(id, new Loop(getPC(), gotoAddr));
+ }
+ }
+ }
}
} finally {
stack.sawOpcode(this, seen);
@@ -179,7 +222,7 @@
}
}
- private int findCollectionGroup(OpcodeStack.Item itm) {
+ private int findCollectionGroup(OpcodeStack.Item itm, boolean addIfNotFound) {
Comparable groupElement = null;
Integer id = (Integer)itm.getUserValue();
@@ -205,12 +248,37 @@
}
}
- Set<Comparable> group = new HashSet<Comparable>();
- group.add(groupElement);
- collectionGroups.add(group);
- return collectionGroups.size() - 1;
+ if (addIfNotFound) {
+ Set<Comparable> group = new HashSet<Comparable>();
+ group.add(groupElement);
+ collectionGroups.add(group);
+ return collectionGroups.size() - 1;
+ }
}
return -1;
}
+
+ class Loop
+ {
+ public int loopStart;
+ public int loopFinish;
+
+ public Loop(int start, int finish) {
+ loopStart = start;
+ loopFinish = finish;
+ }
+
+ public int getLoopFinish() {
+ return loopFinish;
+ }
+
+ public int getLoopStart() {
+ return loopStart;
+ }
+
+ public boolean hasPC(int pc) {
+ return (loopStart <= pc) && (pc <= loopFinish);
+ }
+ }
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2006-12-19 08:16:34
|
Revision: 739
http://svn.sourceforge.net/fb-contrib/?rev=739&view=rev
Author: dbrosius
Date: 2006-12-19 00:16:30 -0800 (Tue, 19 Dec 2006)
Log Message:
-----------
starting to work
Modified Paths:
--------------
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java 2006-12-19 07:41:37 UTC (rev 738)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java 2006-12-19 08:16:30 UTC (rev 739)
@@ -138,8 +138,8 @@
groupId = findCollectionGroup(itm, true);
}
} else if ("remove(Ljava/lang/Object;)Z".equals(methodInfo)) {
- if (stack.getStackDepth() > 0) {
- OpcodeStack.Item itm = stack.getStackItem(0);
+ if (stack.getStackDepth() > 1) {
+ OpcodeStack.Item itm = stack.getStackItem(1);
int id = findCollectionGroup(itm, true);
if (id >= 0) {
Integer it = groupToIterator.get(id);
@@ -196,8 +196,13 @@
if (id != null) {
int target = getBranchTarget();
int gotoAddr = target - 3;
- if (getCode().getCode()[gotoAddr] == GOTO) {
- loops.put(id, new Loop(getPC(), gotoAddr));
+ int ins = getCode().getCode()[gotoAddr];
+ if (ins < 0)
+ ins = 256 + ins;
+ if (ins == GOTO) {
+ Integer reg = groupToIterator.get(id);
+ if (reg != null)
+ loops.put(reg, new Loop(getPC(), gotoAddr));
}
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2006-12-19 21:14:52
|
Revision: 743
http://svn.sourceforge.net/fb-contrib/?rev=743&view=rev
Author: dbrosius
Date: 2006-12-19 13:14:36 -0800 (Tue, 19 Dec 2006)
Log Message:
-----------
guard against odd npes
Modified Paths:
--------------
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java 2006-12-19 13:41:48 UTC (rev 742)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java 2006-12-19 21:14:36 UTC (rev 743)
@@ -178,7 +178,8 @@
int reg = RegisterUtils.getAStoreReg(this, seen);
try {
- if (itm.getJavaClass().implementationOf(iteratorClass)) {
+ JavaClass cls = itm.getJavaClass();
+ if ((cls != null) && cls.implementationOf(iteratorClass)) {
groupToIterator.put(id, Integer14.valueOf(reg));
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2006-12-22 21:32:13
|
Revision: 753
http://svn.sourceforge.net/fb-contrib/?rev=753&view=rev
Author: dbrosius
Date: 2006-12-22 13:32:07 -0800 (Fri, 22 Dec 2006)
Log Message:
-----------
avoid autoboxing
Modified Paths:
--------------
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java 2006-12-22 19:01:24 UTC (rev 752)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java 2006-12-22 21:32:07 UTC (rev 753)
@@ -151,7 +151,7 @@
OpcodeStack.Item itm = stack.getStackItem(1);
int id = findCollectionGroup(itm, true);
if (id >= 0) {
- Integer it = groupToIterator.get(id);
+ Integer it = groupToIterator.get(Integer14.valueOf(id));
Loop loop = loops.get(it);
if (loop != null) {
int pc = getPC();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2006-12-22 21:37:29
|
Revision: 759
http://svn.sourceforge.net/fb-contrib/?rev=759&view=rev
Author: dbrosius
Date: 2006-12-22 13:37:28 -0800 (Fri, 22 Dec 2006)
Log Message:
-----------
avoid autoboxing
Modified Paths:
--------------
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java 2006-12-22 21:36:39 UTC (rev 758)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java 2006-12-22 21:37:28 UTC (rev 759)
@@ -186,7 +186,7 @@
groupToIterator.put(id, Integer14.valueOf(reg));
}
- Set<Comparable> group = collectionGroups.get(id);
+ Set<Comparable> group = collectionGroups.get(id.intValue());
if (group != null) {
group.add(Integer14.valueOf(reg));
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2007-01-28 21:01:53
|
Revision: 800
http://svn.sourceforge.net/fb-contrib/?rev=800&view=rev
Author: dbrosius
Date: 2007-01-28 13:01:52 -0800 (Sun, 28 Jan 2007)
Log Message:
-----------
inner classes s/b static if possible
Modified Paths:
--------------
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java 2007-01-28 21:00:11 UTC (rev 799)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java 2007-01-28 21:01:52 UTC (rev 800)
@@ -274,7 +274,7 @@
return -1;
}
- class Loop
+ static class Loop
{
public int loopStart;
public int loopFinish;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2007-02-06 05:16:30
|
Revision: 841
http://svn.sourceforge.net/fb-contrib/?rev=841&view=rev
Author: dbrosius
Date: 2007-02-05 21:16:30 -0800 (Mon, 05 Feb 2007)
Log Message:
-----------
when loading a collection from a field, keep track of what register the instance who's field is loaded is, to differentiate fields with same name, but different instances.
Modified Paths:
--------------
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java 2007-02-06 03:50:33 UTC (rev 840)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java 2007-02-06 05:16:30 UTC (rev 841)
@@ -280,7 +280,9 @@
else {
XField field = itm.getXField();
if (field != null) {
- groupElement = field.getName();
+ int regLoad = itm.getFieldLoadedFromRegister();
+ if (regLoad >= 0)
+ groupElement = field.getName() + "[" + regLoad + "]";
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2007-02-07 04:52:12
|
Revision: 843
http://svn.sourceforge.net/fb-contrib/?rev=843&view=rev
Author: dbrosius
Date: 2007-02-06 20:52:12 -0800 (Tue, 06 Feb 2007)
Log Message:
-----------
remove some false positives
Modified Paths:
--------------
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java 2007-02-07 01:55:25 UTC (rev 842)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java 2007-02-07 04:52:12 UTC (rev 843)
@@ -35,9 +35,11 @@
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.ba.ClassContext;
import edu.umd.cs.findbugs.ba.XField;
+import edu.umd.cs.findbugs.classfile.FieldDescriptor;
/**
* looks for deletion of items from a collection using the remove method
@@ -64,16 +66,16 @@
collectionMethods.add("keySet()Ljava/lang/Set;");
collectionMethods.add("values()Ljava/lang/Collection;");
}
- private static final Set<String> modifyingMethods = new HashSet<String>();
+ private static final Map<String, Integer> modifyingMethods = new HashMap<String, Integer>();
static {
- modifyingMethods.add("add(Ljava/lang/Object;)Z");
- modifyingMethods.add("addAll(Ljava/util/Collection;)Z");
- modifyingMethods.add("addAll(ILjava/util/Collection;)Z");
- modifyingMethods.add("clear()V");
- modifyingMethods.add("remove(I)Ljava/lang/Object;");
- modifyingMethods.add("removeAll(Ljava/util/Collection;)Z");
- modifyingMethods.add("retainAll(Ljava/util/Collection;)Z");
- modifyingMethods.add("set(ILjava/lang/Object;)Ljava/lang/Object;");
+ modifyingMethods.put("add(Ljava/lang/Object;)Z", Integer14.valueOf(1));
+ modifyingMethods.put("addAll(Ljava/util/Collection;)Z", Integer14.valueOf(1));
+ modifyingMethods.put("addAll(ILjava/util/Collection;)Z", Integer14.valueOf(2));
+ modifyingMethods.put("clear()V", Integer.valueOf(0));
+ modifyingMethods.put("remove(I)Ljava/lang/Object;", Integer14.valueOf(1));
+ modifyingMethods.put("removeAll(Ljava/util/Collection;)Z", Integer14.valueOf(1));
+ modifyingMethods.put("retainAll(Ljava/util/Collection;)Z", Integer14.valueOf(1));
+ modifyingMethods.put("set(ILjava/lang/Object;)Ljava/lang/Object;", Integer14.valueOf(2));
}
@@ -176,20 +178,23 @@
}
}
}
- } else if (modifyingMethods.contains(methodInfo)) {
- if (stack.getStackDepth() > 1) {
- OpcodeStack.Item itm = stack.getStackItem(1);
- int id = findCollectionGroup(itm, true);
- if (id >= 0) {
- Integer it = groupToIterator.get(Integer14.valueOf(id));
- Loop loop = loops.get(it);
- if (loop != null) {
- int pc = getPC();
- if (loop.hasPC(pc)) {
- bugReporter.reportBug(new BugInstance(this, "DWI_MODIFYING_WHILE_ITERATING", NORMAL_PRIORITY)
- .addClass(this)
- .addMethod(this)
- .addSourceLine(this));
+ } else {
+ Integer numArgs = modifyingMethods.get(methodInfo);
+ if (numArgs != null) {
+ if (stack.getStackDepth() > numArgs.intValue()) {
+ OpcodeStack.Item itm = stack.getStackItem(numArgs.intValue());
+ int id = findCollectionGroup(itm, true);
+ if (id >= 0) {
+ Integer it = groupToIterator.get(Integer14.valueOf(id));
+ Loop loop = loops.get(it);
+ if (loop != null) {
+ int pc = getPC();
+ if (loop.hasPC(pc)) {
+ bugReporter.reportBug(new BugInstance(this, "DWI_MODIFYING_WHILE_ITERATING", NORMAL_PRIORITY)
+ .addClass(this)
+ .addMethod(this)
+ .addSourceLine(this));
+ }
}
}
}
@@ -203,7 +208,18 @@
groupId = id.intValue();
}
}
- } else if ((seen == ASTORE) || ((seen >= ASTORE_0) && (seen <= ASTORE_3))) {
+ } else if (seen == PUTFIELD) {
+ if (stack.getStackDepth() > 1) {
+ OpcodeStack.Item itm = stack.getStackItem(0);
+
+ Integer id = (Integer)itm.getUserValue();
+ if (id == null) {
+ FieldAnnotation fa = FieldAnnotation.fromFieldDescriptor(new FieldDescriptor(getClassConstantOperand(), getNameConstantOperand(), getSigConstantOperand(), false));
+ itm = new OpcodeStack.Item(itm.getSignature(), fa, stack.getStackItem(1).getRegisterNumber());
+ removeFromCollectionGroup(itm);
+ }
+ }
+ } else if ((seen == ASTORE) || ((seen >= ASTORE_0) && (seen <= ASTORE_3))) {
if (stack.getStackDepth() > 0) {
OpcodeStack.Item itm = stack.getStackItem(0);
Integer id = (Integer)itm.getUserValue();
@@ -253,7 +269,6 @@
OpcodeStack.Item itm = stack.getStackItem(0);
itm.setUserValue(Integer14.valueOf(groupId));
}
-
}
}
@@ -267,13 +282,9 @@
}
}
- private int findCollectionGroup(OpcodeStack.Item itm, boolean addIfNotFound) {
+ private Comparable getGroupElement(OpcodeStack.Item itm) {
Comparable groupElement = null;
-
- Integer id = (Integer)itm.getUserValue();
- if (id != null)
- return id.intValue();
-
+
int reg = itm.getRegisterNumber();
if (reg >= 0)
groupElement = Integer14.valueOf(reg);
@@ -282,10 +293,20 @@
if (field != null) {
int regLoad = itm.getFieldLoadedFromRegister();
if (regLoad >= 0)
- groupElement = field.getName() + "[" + regLoad + "]";
+ groupElement = field.getName() + ":{" + regLoad + "}";
}
}
-
+
+ return groupElement;
+ }
+
+ private int findCollectionGroup(OpcodeStack.Item itm, boolean addIfNotFound) {
+
+ Integer id = (Integer)itm.getUserValue();
+ if (id != null)
+ return id.intValue();
+
+ Comparable groupElement = getGroupElement(itm);
if (groupElement != null) {
int numGroups = collectionGroups.size();
for (int i = 0; i < numGroups; i++) {
@@ -306,6 +327,20 @@
return -1;
}
+ private void removeFromCollectionGroup(OpcodeStack.Item itm) {
+ Comparable groupElement = getGroupElement(itm);
+ if (groupElement != null) {
+ int numGroups = collectionGroups.size();
+ for (int i = 0; i < numGroups; i++) {
+ Set<? extends Comparable> group = collectionGroups.get(i);
+ if (group.contains(groupElement)) {
+ group.remove(groupElement);
+ break;
+ }
+ }
+ }
+ }
+
static class Loop
{
public int loopStart;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2007-02-13 04:34:15
|
Revision: 850
http://svn.sourceforge.net/fb-contrib/?rev=850&view=rev
Author: dbrosius
Date: 2007-02-12 20:34:14 -0800 (Mon, 12 Feb 2007)
Log Message:
-----------
if an iterator is reused for a new collection, make sure to remove it from the collection group to iterator map
Modified Paths:
--------------
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java 2007-02-09 23:31:55 UTC (rev 849)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java 2007-02-13 04:34:14 UTC (rev 850)
@@ -21,6 +21,7 @@
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
+import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -229,7 +230,13 @@
try {
JavaClass cls = itm.getJavaClass();
if ((cls != null) && cls.implementationOf(iteratorClass)) {
- groupToIterator.put(id, Integer14.valueOf(reg));
+ Integer regIt = Integer14.valueOf(reg);
+ Iterator<Integer> curIt = groupToIterator.values().iterator();
+ while (curIt.hasNext()) {
+ if (curIt.next().equals(regIt))
+ curIt.remove();
+ }
+ groupToIterator.put(id, regIt);
}
Set<Comparable> group = collectionGroups.get(id.intValue());
@@ -362,5 +369,10 @@
public boolean hasPC(int pc) {
return (loopStart <= pc) && (pc <= loopFinish);
}
+
+ @Override
+ public String toString() {
+ return "Start=" + loopStart + " Finish=" + loopFinish;
+ }
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2007-02-13 23:58:58
|
Revision: 854
http://svn.sourceforge.net/fb-contrib/?rev=854&view=rev
Author: dbrosius
Date: 2007-02-13 15:58:59 -0800 (Tue, 13 Feb 2007)
Log Message:
-----------
rid the world of 1.5 methods
Modified Paths:
--------------
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java 2007-02-13 23:35:42 UTC (rev 853)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java 2007-02-13 23:58:59 UTC (rev 854)
@@ -72,7 +72,7 @@
modifyingMethods.put("add(Ljava/lang/Object;)Z", Integer14.valueOf(1));
modifyingMethods.put("addAll(Ljava/util/Collection;)Z", Integer14.valueOf(1));
modifyingMethods.put("addAll(ILjava/util/Collection;)Z", Integer14.valueOf(2));
- modifyingMethods.put("clear()V", Integer.valueOf(0));
+ modifyingMethods.put("clear()V", Integer14.valueOf(0));
modifyingMethods.put("remove(I)Ljava/lang/Object;", Integer14.valueOf(1));
modifyingMethods.put("removeAll(Ljava/util/Collection;)Z", Integer14.valueOf(1));
modifyingMethods.put("retainAll(Ljava/util/Collection;)Z", Integer14.valueOf(1));
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2007-03-11 15:11:04
|
Revision: 880
http://svn.sourceforge.net/fb-contrib/?rev=880&view=rev
Author: dbrosius
Date: 2007-03-11 08:11:02 -0700 (Sun, 11 Mar 2007)
Log Message:
-----------
LII simplifications
Modified Paths:
--------------
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java 2007-03-11 15:08:46 UTC (rev 879)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java 2007-03-11 15:11:02 UTC (rev 880)
@@ -337,9 +337,7 @@
private void removeFromCollectionGroup(OpcodeStack.Item itm) {
Comparable groupElement = getGroupElement(itm);
if (groupElement != null) {
- int numGroups = collectionGroups.size();
- for (int i = 0; i < numGroups; i++) {
- Set<? extends Comparable> group = collectionGroups.get(i);
+ for (Set<? extends Comparable> group : collectionGroups) {
if (group.contains(groupElement)) {
group.remove(groupElement);
break;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2007-03-13 03:31:20
|
Revision: 881
http://svn.sourceforge.net/fb-contrib/?rev=881&view=rev
Author: dbrosius
Date: 2007-03-12 20:31:20 -0700 (Mon, 12 Mar 2007)
Log Message:
-----------
if you can't find an iterator for a group, short-circuit the attempt to find a modifying statement
Modified Paths:
--------------
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java 2007-03-11 15:11:02 UTC (rev 880)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java 2007-03-13 03:31:20 UTC (rev 881)
@@ -187,14 +187,16 @@
int id = findCollectionGroup(itm, true);
if (id >= 0) {
Integer it = groupToIterator.get(Integer14.valueOf(id));
- Loop loop = loops.get(it);
- if (loop != null) {
- int pc = getPC();
- if (loop.hasPC(pc)) {
- bugReporter.reportBug(new BugInstance(this, "DWI_MODIFYING_WHILE_ITERATING", NORMAL_PRIORITY)
- .addClass(this)
- .addMethod(this)
- .addSourceLine(this));
+ if (it != null) {
+ Loop loop = loops.get(it);
+ if (loop != null) {
+ int pc = getPC();
+ if (loop.hasPC(pc)) {
+ bugReporter.reportBug(new BugInstance(this, "DWI_MODIFYING_WHILE_ITERATING", NORMAL_PRIORITY)
+ .addClass(this)
+ .addMethod(this)
+ .addSourceLine(this));
+ }
}
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2007-09-23 05:16:31
|
Revision: 918
http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=918&view=rev
Author: dbrosius
Date: 2007-09-22 22:16:33 -0700 (Sat, 22 Sep 2007)
Log Message:
-----------
warnings
Modified Paths:
--------------
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java 2007-09-19 05:03:28 UTC (rev 917)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java 2007-09-23 05:16:33 UTC (rev 918)
@@ -82,7 +82,7 @@
private BugReporter bugReporter;
private OpcodeStack stack;
- private List<Set<Comparable>> collectionGroups;
+ private List<Set<Comparable<?>>> collectionGroups;
private Map<Integer, Integer> groupToIterator;
private Map<Integer, Loop> loops;
@@ -106,7 +106,7 @@
try {
stack = new OpcodeStack();
- collectionGroups = new ArrayList<Set<Comparable>>();
+ collectionGroups = new ArrayList<Set<Comparable<?>>>();
groupToIterator = new HashMap<Integer, Integer>();
loops = new HashMap<Integer, Loop>();
super.visitClassContext(classContext);
@@ -241,7 +241,7 @@
groupToIterator.put(id, regIt);
}
- Set<Comparable> group = collectionGroups.get(id.intValue());
+ Set<Comparable<?>> group = collectionGroups.get(id.intValue());
if (group != null) {
group.add(Integer14.valueOf(reg));
}
@@ -291,8 +291,8 @@
}
}
- private Comparable getGroupElement(OpcodeStack.Item itm) {
- Comparable groupElement = null;
+ private Comparable<?> getGroupElement(OpcodeStack.Item itm) {
+ Comparable<?> groupElement = null;
int reg = itm.getRegisterNumber();
if (reg >= 0)
@@ -315,18 +315,18 @@
if (id != null)
return id.intValue();
- Comparable groupElement = getGroupElement(itm);
+ Comparable<?> groupElement = getGroupElement(itm);
if (groupElement != null) {
int numGroups = collectionGroups.size();
for (int i = 0; i < numGroups; i++) {
- Set<? extends Comparable> group = collectionGroups.get(i);
+ Set<? extends Comparable<?>> group = collectionGroups.get(i);
if (group.contains(groupElement)) {
return i;
}
}
if (addIfNotFound) {
- Set<Comparable> group = new HashSet<Comparable>();
+ Set<Comparable<?>> group = new HashSet<Comparable<?>>();
group.add(groupElement);
collectionGroups.add(group);
return collectionGroups.size() - 1;
@@ -337,9 +337,9 @@
}
private void removeFromCollectionGroup(OpcodeStack.Item itm) {
- Comparable groupElement = getGroupElement(itm);
+ Comparable<?> groupElement = getGroupElement(itm);
if (groupElement != null) {
- for (Set<? extends Comparable> group : collectionGroups) {
+ for (Set<? extends Comparable<?>> group : collectionGroups) {
if (group.contains(groupElement)) {
group.remove(groupElement);
break;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2008-06-09 18:06:59
|
Revision: 1048
http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1048&view=rev
Author: dbrosius
Date: 2008-06-09 11:06:22 -0700 (Mon, 09 Jun 2008)
Log Message:
-----------
suppress deprecation
Modified Paths:
--------------
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java 2008-06-08 16:03:17 UTC (rev 1047)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java 2008-06-09 18:06:22 UTC (rev 1048)
@@ -363,6 +363,7 @@
if (lvt != null) {
int len = lvt.getLength();
for (int i = 0; i < len; i++) {
+ @SuppressWarnings("deprecation")
LocalVariable lv = lvt.getLocalVariable(i);
if (lv != null) {
Integer endPC = Integer14.valueOf(lv.getStartPC() + lv.getLength());
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2008-03-23 05:10:49
|
Revision: 1013
http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1013&view=rev
Author: dbrosius
Date: 2008-03-22 22:10:55 -0700 (Sat, 22 Mar 2008)
Log Message:
-----------
need to remove registers from collection groups when that variable goes out of scope
Modified Paths:
--------------
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java 2008-03-20 05:39:32 UTC (rev 1012)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java 2008-03-23 05:10:55 UTC (rev 1013)
@@ -29,6 +29,8 @@
import org.apache.bcel.Repository;
import org.apache.bcel.classfile.Code;
import org.apache.bcel.classfile.JavaClass;
+import org.apache.bcel.classfile.LocalVariable;
+import org.apache.bcel.classfile.LocalVariableTable;
import com.mebigfatguy.fbcontrib.utils.Integer14;
import com.mebigfatguy.fbcontrib.utils.RegisterUtils;
@@ -85,6 +87,7 @@
private List<Set<Comparable<?>>> collectionGroups;
private Map<Integer, Integer> groupToIterator;
private Map<Integer, Loop> loops;
+ private Map<Integer, Set<Integer>> endOfScopes;
/**
* constructs a DWI detector given the reporter to report bugs on
@@ -115,6 +118,7 @@
collectionGroups = null;
groupToIterator = null;
loops = null;
+ endOfScopes = null;
}
}
@@ -129,6 +133,8 @@
collectionGroups.clear();
groupToIterator.clear();
loops.clear();
+ buildVariableEndScopeMap();
+
super.visitCode(obj);
}
@@ -278,6 +284,8 @@
OpcodeStack.Item itm = stack.getStackItem(0);
itm.setUserValue(Integer14.valueOf(groupId));
}
+
+ processEndOfScopes(Integer14.valueOf(getPC()));
}
}
@@ -348,6 +356,42 @@
}
}
+ private void buildVariableEndScopeMap() {
+ endOfScopes = new HashMap<Integer, Set<Integer>>();
+
+ LocalVariableTable lvt = getMethod().getLocalVariableTable();
+ if (lvt != null) {
+ int len = lvt.getLength();
+ for (int i = 0; i < len; i++) {
+ LocalVariable lv = lvt.getLocalVariable(i);
+ if (lv != null) {
+ Integer endPC = Integer14.valueOf(lv.getStartPC() + lv.getLength());
+ Set<Integer> vars = endOfScopes.get(endPC);
+ if (vars == null) {
+ vars = new HashSet<Integer>();
+ endOfScopes.put(endPC, vars);
+ }
+ vars.add(Integer14.valueOf(lv.getIndex()));
+ }
+ }
+ }
+ }
+
+ private void processEndOfScopes(Integer pc) {
+ Set<Integer> endVars = endOfScopes.get(pc);
+ if (endVars != null) {
+ for (Integer v : endVars) {
+ Iterator<Set<Comparable<?>>> it = collectionGroups.iterator();
+ while (it.hasNext()) {
+ Set<Comparable<?>> gv = it.next();
+ if (gv.contains(v)) {
+ gv.remove(v);
+ }
+ }
+ }
+ }
+ }
+
static class Loop
{
public int loopStart;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2008-07-11 03:57:55
|
Revision: 1060
http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1060&view=rev
Author: dbrosius
Date: 2008-07-10 20:58:04 -0700 (Thu, 10 Jul 2008)
Log Message:
-----------
don't report DWI if the next statement is a break.
Modified Paths:
--------------
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java 2008-07-11 03:40:42 UTC (rev 1059)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java 2008-07-11 03:58:04 UTC (rev 1060)
@@ -26,12 +26,14 @@
import java.util.Map;
import java.util.Set;
+import org.apache.bcel.Constants;
import org.apache.bcel.Repository;
import org.apache.bcel.classfile.Code;
import org.apache.bcel.classfile.JavaClass;
import org.apache.bcel.classfile.LocalVariable;
import org.apache.bcel.classfile.LocalVariableTable;
+import com.mebigfatguy.fbcontrib.utils.CodeByteUtils;
import com.mebigfatguy.fbcontrib.utils.Integer14;
import com.mebigfatguy.fbcontrib.utils.RegisterUtils;
@@ -177,10 +179,25 @@
if (loop != null) {
int pc = getPC();
if (loop.hasPC(pc)) {
- bugReporter.reportBug(new BugInstance(this, "DWI_DELETING_WHILE_ITERATING", NORMAL_PRIORITY)
- .addClass(this)
- .addMethod(this)
- .addSourceLine(this));
+ boolean breakFollows = false;
+ byte[] code = getCode().getCode();
+ int nextPC = getNextPC();
+ int popOp = CodeByteUtils.getbyte(code, nextPC++);
+ if (popOp == Constants.POP) {
+ int gotoOp = CodeByteUtils.getbyte(code, nextPC);
+ if (gotoOp == Constants.GOTO) {
+ int target = nextPC + CodeByteUtils.getshort(code, nextPC+1);
+ if (target > loop.getLoopFinish())
+ breakFollows = true;
+ }
+ }
+
+ if (!breakFollows) {
+ bugReporter.reportBug(new BugInstance(this, "DWI_DELETING_WHILE_ITERATING", NORMAL_PRIORITY)
+ .addClass(this)
+ .addMethod(this)
+ .addSourceLine(this));
+ }
}
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|