data race

This commit is contained in:
Alexey Kudravtsev
2011-02-22 20:47:47 +03:00
parent d151f3013f
commit 12eae7ea00
2 changed files with 15 additions and 5 deletions
@@ -27,7 +27,8 @@ import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.util.containers.WeakList;
import org.jetbrains.annotations.NotNull;
import java.util.Iterator;
import java.util.ArrayList;
import java.util.List;
/**
* Date: Mar 17, 2009
@@ -39,14 +40,16 @@ public class LazyRangeMarkerFactory extends AbstractProjectComponent {
super(project);
EditorFactory.getInstance().getEventMulticaster().addDocumentListener(new DocumentAdapter() {
public void beforeDocumentChange(DocumentEvent e) {
for (Iterator<LazyMarker> it = myMarkers.iterator(); it.hasNext();) {
final LazyMarker marker = it.next();
List<LazyMarker> markers = myMarkers.toStrongList();
List<LazyMarker> markersToRemove = new ArrayList<LazyMarker>();
for (final LazyMarker marker : markers) {
final VirtualFile docFile = fileDocumentManager.getFile(e.getDocument());
if (marker.getFile() == docFile) {
marker.ensureDelegate();
it.remove();
markersToRemove.add(marker);
}
}
myMarkers.removeAll(markersToRemove);
}
}, project);
}
@@ -76,6 +76,13 @@ public class WeakList<T> extends AbstractList<T> {
}
}
@Override
public boolean removeAll(Collection<?> c) {
synchronized (myArray) {
return super.removeAll(c);
}
}
public Iterator<T> iterator() {
return new MyIterator();
}
@@ -88,7 +95,7 @@ public class WeakList<T> extends AbstractList<T> {
public List<T> toStrongList() {
synchronized (myArray) {
List<T> result = new ArrayList<T>();
List<T> result = new ArrayList<T>(myArray.size());
myArray.toStrongCollection(result);
return result;
}