[Fb-contrib-commit] fb-contrib/src/com/mebigfatguy/fbcontrib/detect SyncCollectionIterators.java,1.5
Brought to you by:
dbrosius
|
From: Dave B. <dbr...@us...> - 2005-11-05 02:23:35
|
Update of /cvsroot/fb-contrib/fb-contrib/src/com/mebigfatguy/fbcontrib/detect In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30417/src/com/mebigfatguy/fbcontrib/detect Modified Files: SyncCollectionIterators.java Log Message: if a synchronized collection has a synchronized block around it's iterator don't report it. -- for now. Revisit this later especially if the synchronizing object is not the collection itself. Index: SyncCollectionIterators.java =================================================================== RCS file: /cvsroot/fb-contrib/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SyncCollectionIterators.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- SyncCollectionIterators.java 1 Oct 2005 07:38:02 -0000 1.5 +++ SyncCollectionIterators.java 5 Nov 2005 02:23:26 -0000 1.6 @@ -28,6 +28,7 @@ import edu.umd.cs.findbugs.BugInstance; import edu.umd.cs.findbugs.BugReporter; import edu.umd.cs.findbugs.BytecodeScanningDetector; +import edu.umd.cs.findbugs.OpcodeStack; import edu.umd.cs.findbugs.StatelessDetector; import edu.umd.cs.findbugs.ba.ClassContext; @@ -56,6 +57,7 @@ private int state; private Set<String> memberCollections = new HashSet<String>(); private Set<Integer> localCollections = new HashSet<Integer>(); + private int monitorCount; public SyncCollectionIterators(final BugReporter bugReporter) { this.bugReporter = bugReporter; @@ -77,6 +79,7 @@ if (obj.getCode() != null) { state = SEEN_NOTHING; localCollections.clear(); + monitorCount = 0; super.visitCode(obj); } } @@ -136,14 +139,17 @@ } } else if (calledClass.startsWith("java/util/")) { if ("iterator".equals(getNameConstantOperand())) { - bugReporter.reportBug( new BugInstance( this, "SCI_SYNCHRONIZED_COLLECTION_ITERATORS", NORMAL_PRIORITY) - .addClass(this) - .addMethod(this) - .addSourceLine(this)); - state = SEEN_NOTHING; + if (monitorCount == 0) { + bugReporter.reportBug( new BugInstance( this, "SCI_SYNCHRONIZED_COLLECTION_ITERATORS", NORMAL_PRIORITY) + .addClass(this) + .addMethod(this) + .addSourceLine(this)); + state = SEEN_NOTHING; + } else { + state = SEEN_NOTHING; + } } - } - else { + } else { state = SEEN_NOTHING; } } else { @@ -151,5 +157,11 @@ } break; } + + if (seen == MONITORENTER) { + monitorCount++; + } else if (seen == MONITOREXIT) { + monitorCount--; + } } } |