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
*/
	protected IRegion getSignedSelection(ISourceViewer sourceViewer) {
		StyledText text= sourceViewer.getTextWidget();
		Point selection= text.getSelectionRange();
		
		if (text.getCaretOffset() == selection.x) {
			selection.x= selection.x + selection.y;
			selection.y= -selection.y;
		}
		
		selection.x= widgetOffset2ModelOffset(sourceViewer, selection.x);
		
		return new Region(selection.x, selection.y);
	}
	
	private static boolean isBracket(char character) {
		for (int i= 0; i != BRACKETS.length; ++i)
			if (character == BRACKETS[i])
				return true;
		return false;
	}
	private static boolean isSurroundedByBrackets(IDocument document, int offset) {
		if (offset == 0 || offset == document.getLength())
			return false;
		try {
			return
				isBracket(document.getChar(offset - 1)) &&
				isBracket(document.getChar(offset));
			
		} catch (BadLocationException e) {