Bug 18015 NPE in structured selection if file opened from repo
F1 1. repository view - open a java file 2. use structured selection java.lang.NullPointerException at org.eclipse.jdt.internal.ui.javaeditor.structureselection.StructureSelectionActi on.getNewSelectionRange(StructureSelectionAction.java:68) at org.eclipse.jdt.internal.ui.javaeditor.structureselection.StructureSelectionActi on.run(StructureSelectionAction.java:53) at org.eclipse.ui.texteditor.RetargetTextEditorAction.run (RetargetTextEditorAction.java:127) at org.eclipse.jface.action.Action.runWithEvent(Action.java:590) at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection (ActionContributionItem.java:407) at org.eclipse.jface.action.ActionContributionItem.handleWidgetEvent (ActionContributionItem.java:361) at org.eclipse.jface.action.ActionContributionItem.access$0 (ActionContributionItem.java:352) at org.eclipse.jface.action.ActionContributionItem$ActionListener.handleEvent (ActionContributionItem.java:47) at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:75) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:825) at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:1527) at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:1289) at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:1085) at org.eclipse.ui.internal.Workbench.run(Workbench.java:1068) at org.eclipse.core.internal.boot.InternalBootLoader.run (InternalBootLoader.java:739) at org.eclipse.core.boot.BootLoader.run(BootLoader.java:432) at EclipseRuntimeLauncher.main(EclipseRuntimeLauncher.java:24)
org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/structureselection/StructureSelectionAction.java
fSelectionHistory.ignoreSelectionChanges();
			fEditor.selectAndReveal(newRange.getOffset(), newRange.getLength());
		} finally {
			fSelectionHistory.listenToSelectionChanges();
		}
	}
	
	public final ISourceRange getNewSelectionRange(ISourceRange oldSourceRange, ICompilationUnit cu){
		try{
			if (! cu.isStructureKnown())
				return oldSourceRange;
			CompilationUnit root= AST.parseCompilationUnit(cu, false);
			Selection selection= Selection.createFromStartLength(oldSourceRange.getOffset(), oldSourceRange.getLength());
			StructureSelectionAnalyzer selAnalyzer= new StructureSelectionAnalyzer(selection, true);
			root.accept(selAnalyzer);
			return internalGetNewSelectionRange(oldSourceRange, cu, selAnalyzer);
	 	}	catch (JavaModelException e){
	 		JavaPlugin.log(e); 
	 		return new SourceRange(oldSourceRange.getOffset(), oldSourceRange.getLength());
	 	}
	}
	
	/**
	 * This is the default implementation - it goes up one level in the AST.
	 * Subclasses may implement different behavior and/or use this implementation as a fallback for cases they do not handle..
	 */
	abstract ISourceRange internalGetNewSelectionRange(ISourceRange oldSourceRange, ICompilationUnit cu, StructureSelectionAnalyzer selAnalyzer) throws JavaModelException;
	
	protected final ICompilationUnit getCompilationUnit() {
		return JavaPlugin.getDefault().getWorkingCopyManager().getWorkingCopy(fEditor.getEditorInput());