From 48687d7a1fdb2d80b76d3fcb50af0f5ee340e240 Mon Sep 17 00:00:00 2001 From: Gunnlaugur Thor Briem Date: Wed, 21 Apr 2004 02:33:04 +0000 Subject: [PATCH] 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 --- .../src/pmd/scan/PMDScanAnnotation.java | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/pmd-netbeans/src/pmd/scan/PMDScanAnnotation.java b/pmd-netbeans/src/pmd/scan/PMDScanAnnotation.java index 8b9b560377..73cbc3b546 100644 --- a/pmd-netbeans/src/pmd/scan/PMDScanAnnotation.java +++ b/pmd-netbeans/src/pmd/scan/PMDScanAnnotation.java @@ -35,11 +35,10 @@ import org.openide.text.Annotation; 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 - * - * @author ole martin mørk - * @created 3. november 2002 + * PEND: investigate implications of static field here ... seems like we get + * multiple scanners interfering with each other because of this shared state. */ public class PMDScanAnnotation extends Annotation implements PropertyChangeListener { @@ -51,16 +50,20 @@ public class PMDScanAnnotation extends Annotation implements PropertyChangeListe public static final PMDScanAnnotation getNewInstance() { PMDScanAnnotation pmd = new PMDScanAnnotation(); - annotations.add( pmd ); + synchronized(annotations) { + annotations.add( pmd ); + } return pmd; } public static final void clearAll() { - Iterator iterator = annotations.iterator(); - while( iterator.hasNext() ) { - ((Annotation)iterator.next()).detach(); + synchronized(annotations) { + Iterator iterator = annotations.iterator(); + while( iterator.hasNext() ) { + ((Annotation)iterator.next()).detach(); + } + annotations.clear(); } - annotations.clear(); } /**