diff --git a/bundles/org.eclipse.text/src/org/eclipse/jface/text/source/AnnotationModel.java b/bundles/org.eclipse.text/src/org/eclipse/jface/text/source/AnnotationModel.java index 4d24a5f14cf..9e1e16df6a7 100644 --- a/bundles/org.eclipse.text/src/org/eclipse/jface/text/source/AnnotationModel.java +++ b/bundles/org.eclipse.text/src/org/eclipse/jface/text/source/AnnotationModel.java @@ -640,13 +640,25 @@ private void cleanup(boolean fireModelChanged, boolean forkNotification) { fDocumentChanged= false; ArrayList deleted= new ArrayList<>(); - Iterator e= getAnnotationMap().keySetIterator(); IAnnotationMap annotations= getAnnotationMap(); - while (e.hasNext()) { - Annotation a= e.next(); - Position p= annotations.get(a); - if (p == null || p.isDeleted()) - deleted.add(a); + Object mapLock = annotations.getLockObject(); + + if (mapLock == null) { + Iterator e= annotations.keySetIterator(); + while (e.hasNext()) { + Annotation a= e.next(); + Position p= annotations.get(a); + if (p == null || p.isDeleted()) + deleted.add(a); + } + } else { + synchronized (mapLock) { + annotations.forEach((a, p) -> { + if (p == null || p.isDeleted()) { + deleted.add(a); + } + }); + } } if (fireModelChanged && forkNotification) {