diff options
author | Karsten Thoms | 2019-10-28 16:43:18 +0000 |
---|---|---|
committer | Mickael Istria | 2019-10-28 18:52:24 +0000 |
commit | 8797cf932e7412843f0b3b1eec68c5d299bc58b6 (patch) | |
tree | 8711bc838a8051d47285ae5094db64172a7cec25 | |
parent | df9dfa9ffc21130c92f18bfe7b9a268121780c36 (diff) | |
download | eclipse.platform.text-I20191104-1800.tar.gz eclipse.platform.text-I20191104-1800.tar.xz eclipse.platform.text-I20191104-1800.zip |
Bug 552475 - applyHighlights(): Guard against null annotation modelI20191105-0025I20191104-1800I20191103-1800I20191102-1800I20191101-1800I20191101-0300I20191031-1800I20191031-1325I20191030-1800I20191030-0010I20191029-1800I20191028-1800
sourceViewer.getAnnotationModel() might return null, which could cause a
NPE when not guarded. Also set fOccurrenceAnnotations to null when no
current annotation model is present.
Change-Id: Id37edf61ddfb8bbfb329b4282386e30095400190
Signed-off-by: Karsten Thoms <karsten.thoms@itemis.de>
-rw-r--r-- | org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/DefaultWordHighlightStrategy.java | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/DefaultWordHighlightStrategy.java b/org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/DefaultWordHighlightStrategy.java index d5bdcbadd8b..f7385d7810e 100644 --- a/org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/DefaultWordHighlightStrategy.java +++ b/org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/DefaultWordHighlightStrategy.java @@ -105,18 +105,22 @@ public class DefaultWordHighlightStrategy implements IReconcilingStrategy, IReco } IAnnotationModel annotationModel = sourceViewer.getAnnotationModel(); - synchronized (getLockObject(annotationModel)) { - if (annotationModel instanceof IAnnotationModelExtension) { - ((IAnnotationModelExtension) annotationModel).replaceAnnotations(fOccurrenceAnnotations, annotationMap); - } else { - removeOccurrenceAnnotations(); - Iterator<Entry<Annotation, Position>> iter = annotationMap.entrySet().iterator(); - while (iter.hasNext()) { - Entry<Annotation, Position> mapEntry = iter.next(); - annotationModel.addAnnotation(mapEntry.getKey(), mapEntry.getValue()); + if (annotationModel != null) { + synchronized (getLockObject(annotationModel)) { + if (annotationModel instanceof IAnnotationModelExtension) { + ((IAnnotationModelExtension) annotationModel).replaceAnnotations(fOccurrenceAnnotations, annotationMap); + } else { + removeOccurrenceAnnotations(); + Iterator<Entry<Annotation, Position>> iter = annotationMap.entrySet().iterator(); + while (iter.hasNext()) { + Entry<Annotation, Position> mapEntry = iter.next(); + annotationModel.addAnnotation(mapEntry.getKey(), mapEntry.getValue()); + } } + fOccurrenceAnnotations = annotationMap.keySet().toArray(new Annotation[annotationMap.keySet().size()]); } - fOccurrenceAnnotations = annotationMap.keySet().toArray(new Annotation[annotationMap.keySet().size()]); + } else { + fOccurrenceAnnotations = null; } } |