Add synchronization to avoid concurrent-modification exceptions.

Still need to rethink that use of a static field. Seems suspect.


git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@2646 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
Gunnlaugur Thor Briem
2004-04-21 02:33:04 +00:00
parent 3e009f0d0a
commit 48687d7a1f

View File

@ -35,11 +35,10 @@ import org.openide.text.Annotation;
import org.openide.text.Line; import org.openide.text.Line;
/** /**
* Just a class thats mission is to mark the line where the error is. It's using * Just a class whose mission is to mark the line where the error is. It's using
* pmd-annotation type to mark the line * pmd-annotation type to mark the line
* * PEND: investigate implications of static field here ... seems like we get
* @author ole martin mørk * multiple scanners interfering with each other because of this shared state.
* @created 3. november 2002
*/ */
public class PMDScanAnnotation extends Annotation implements PropertyChangeListener { public class PMDScanAnnotation extends Annotation implements PropertyChangeListener {
@ -51,16 +50,20 @@ public class PMDScanAnnotation extends Annotation implements PropertyChangeListe
public static final PMDScanAnnotation getNewInstance() { public static final PMDScanAnnotation getNewInstance() {
PMDScanAnnotation pmd = new PMDScanAnnotation(); PMDScanAnnotation pmd = new PMDScanAnnotation();
annotations.add( pmd ); synchronized(annotations) {
annotations.add( pmd );
}
return pmd; return pmd;
} }
public static final void clearAll() { public static final void clearAll() {
Iterator iterator = annotations.iterator(); synchronized(annotations) {
while( iterator.hasNext() ) { Iterator iterator = annotations.iterator();
((Annotation)iterator.next()).detach(); while( iterator.hasNext() ) {
((Annotation)iterator.next()).detach();
}
annotations.clear();
} }
annotations.clear();
} }
/** /**