Bug 552475 - applyHighlights(): Guard against null annotation model

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>
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 d5bdcba..f7385d7 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 @@
 		}
 
 		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;
 		}
 	}