Bug 57176 NPE while editing Java source file
3.0 M8 Happened a couple of times today, not sure what exact action I was executing. Except for an error dialog, and the log entry, it would go unnoticed (no noticeable change in behaviour). Sorry, no test case. !ENTRY org.eclipse.core.runtime 4 2 Apr 01, 2004 22:30:42.857 !MESSAGE Problems occurred when invoking code from plug-in: "org.eclipse.core.ru ntime". !STACK 0 java.lang.NullPointerException at org.eclipse.jdt.internal.ui.javaeditor.JavaEditor.setSelection(JavaEd itor.java:2338) at org.eclipse.jdt.internal.ui.javaeditor.JavaEditor.doSelectionChanged( JavaEditor.java:2482) at org.eclipse.jdt.internal.ui.javaeditor.JavaEditor$OutlineSelectionCha ngedListener.selectionChanged(JavaEditor.java:291) at org.eclipse.jface.viewers.StructuredViewer$3.run(StructuredViewer.jav a:431) at org.eclipse.core.internal.runtime.InternalPlatform.run(InternalPlatfo rm.java:610) at org.eclipse.core.runtime.Platform.run(Platform.java:521) at org.eclipse.jface.viewers.StructuredViewer.firePostSelectionChanged(S tructuredViewer.java:429) at org.eclipse.jface.viewers.StructuredViewer.handleInvalidSelection(Str ucturedViewer.java:636) at org.eclipse.jface.viewers.StructuredViewer.preservingSelection(Struct uredViewer.java:822) at org.eclipse.jface.viewers.StructuredViewer.refresh(StructuredViewer.j ava:893) at org.eclipse.jface.viewers.StructuredViewer.refresh(StructuredViewer.j ava:853) at org.eclipse.jdt.internal.ui.javaeditor.JavaOutlinePage$JavaOutlineVie wer.reconcile(JavaOutlinePage.java:405) at org.eclipse.jdt.internal.ui.javaeditor.JavaOutlinePage$1.run(JavaOutl inePage.java:168) at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35) at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.ja va:106) at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:2555) at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2260) at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:1562) at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:1536) at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.jav a:257) at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:139) at org.eclipse.ui.internal.ide.IDEApplication.run(IDEApplication.java:90 ) at org.eclipse.core.internal.runtime.PlatformActivator$1.run(PlatformAct ivator.java:277) at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.ja va:239) at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.ja va:117) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl. java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces sorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:324) at org.eclipse.core.launcher.Main.basicRun(Main.java:267) at org.eclipse.core.launcher.Main.run(Main.java:692) at org.eclipse.core.launcher.Main.main(Main.java:676)
org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/JavaEditor.java
try {					
				StyledText text= viewer.getTextWidget();			
				if (text == null || text.isDisposed())
					return -1;
				Display display= text.getDisplay();				
				Point absolutePosition= display.getCursorLocation();
				Point relativePosition= text.toControl(absolutePosition);
				
				int widgetOffset= text.getOffsetAtLocation(relativePosition);
				if (viewer instanceof ITextViewerExtension5) {
					ITextViewerExtension5 extension= (ITextViewerExtension5) viewer;
					return extension.widgetOffset2ModelOffset(widgetOffset);
				} else {
					return widgetOffset + viewer.getVisibleRegion().getOffset();
				}
			} catch (IllegalArgumentException e) {
				return -1;
			}			
		}
		public void applyTextPresentation(TextPresentation textPresentation) {
			if (fActiveRegion == null)
				return;
			IRegion region= textPresentation.getExtent();
			if (fActiveRegion.getOffset() + fActiveRegion.getLength() >= region.getOffset() && region.getOffset() + region.getLength() > fActiveRegion.getOffset())
				textPresentation.mergeStyleRange(new StyleRange(fActiveRegion.getOffset(), fActiveRegion.getLength(), fColor, null));
		}
		
		private void highlightRegion(ISourceViewer viewer, IRegion region) {
			if (region.equals(fActiveRegion))
				return;