Bug 31687 NPE in FindOccurrencesEngine.create
I create a Java editor in plug-in code. It comes up ok but when I select a word and do the "Search...Occurrences in File" action it bombs with the traceback below. Here is the plug-in code that creates the editor: IWorkbenchPage page = PlatformUI.getWorkbench ().getActiveWorkbenchWindow().getActivePage(); if (page == null) return; IStorage storage = new FileStorage(path); IEditorRegistry registry= PlatformUI.getWorkbench().getEditorRegistry (); IEditorDescriptor desc = registry.getDefaultEditor(fileName); if (desc == null) { desc = registry.getDefaultEditor(); } IEditorInput input = new ExternalEditorInput(storage); IEditorPart editor = page.openEditor(input, desc.getId()); FileStorage and ExternalEditorInput are my own classes that I based on examples from JDT (jar reading) and CDT. I can attach them if needed. The problem seems to be that CompilationUnitDocumentProvider.getWorkingCopy is returning null because getElementInfo isn't returning a CompilationUnitInfo (an internal class). It's unclear to me if this is something I'm not setting up properly in my code or if the find engine should be doing something differently. /* * @see IWorkingCopyManager#getWorkingCopy(Object) */ public ICompilationUnit getWorkingCopy(IEditorInput element) { ElementInfo elementInfo= getElementInfo(element); if (elementInfo instanceof CompilationUnitInfo) { CompilationUnitInfo info= (CompilationUnitInfo) elementInfo; return info.fCopy; } return null; } Here's the traceback: Thread [main] (Suspended (exception java.lang.NullPointerException)) org.eclipse.jdt.internal.ui.search.FindOccurrencesEngine.create (org.eclipse.jdt.core.IJavaElement) line: 127 org.eclipse.jdt.ui.actions.FindOccurrencesInFileAction.run (org.eclipse.jface.text.ITextSelection) line: 163 org.eclipse.jdt.ui.actions.FindOccurrencesInFileAction (org.eclipse.jdt.ui.actions.SelectionDispatchAction).dispatchRun (org.eclipse.jface.viewers.ISelection) line: 193 org.eclipse.jdt.ui.actions.FindOccurrencesInFileAction (org.eclipse.jdt.ui.actions.SelectionDispatchAction).run() line: 169 org.eclipse.jdt.ui.actions.FindOccurrencesInFileAction (org.eclipse.jface.action.Action).runWithEvent(org.eclipse.swt.widgets.Event) line: 804 org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection (org.eclipse.swt.widgets.Event) line: 450 org.eclipse.jface.action.ActionContributionItem.handleWidgetEvent (org.eclipse.swt.widgets.Event) line: 398 org.eclipse.jface.action.ActionContributionItem.access$0 (org.eclipse.jface.action.ActionContributionItem, org.eclipse.swt.widgets.Event) line: 392 org.eclipse.jface.action.ActionContributionItem$ActionListener.handleEv ent(org.eclipse.swt.widgets.Event) line: 72 org.eclipse.swt.widgets.EventTable.sendEvent (org.eclipse.swt.widgets.Event) line: 77 org.eclipse.swt.widgets.MenuItem (org.eclipse.swt.widgets.Widget).sendEvent(org.eclipse.swt.widgets.Event) line: 836 org.eclipse.swt.widgets.Display.runDeferredEvents() line: 1692 org.eclipse.swt.widgets.Display.readAndDispatch() line: 1410 org.eclipse.ui.internal.Workbench.runEventLoop (org.eclipse.jface.window.Window$IExceptionHandler) line: 1289 org.eclipse.ui.internal.Workbench.run(java.lang.Object) line: 1272 org.eclipse.core.internal.boot.InternalBootLoader.run (java.lang.String, java.net.URL, java.lang.String, java.lang.String[], java.lang.Runnable) line: 845 org.eclipse.core.boot.BootLoader.run(java.lang.String, java.net.URL, java.lang.String, java.lang.String[], java.lang.Runnable) line: 461 sun.reflect.NativeMethodAccessorImpl.invoke0(java.lang.reflect.Method, java.lang.Object, java.lang.Object[]) line: not available [native method] sun.reflect.NativeMethodAccessorImpl.invoke(java.lang.Object, java.lang.Object[]) line: 39 [local variables unavailable] sun.reflect.DelegatingMethodAccessorImpl.invoke(java.lang.Object, java.lang.Object[]) line: 25 [local variables unavailable] java.lang.reflect.Method.invoke(java.lang.Object, java.lang.Object[]) line: 324 [local variables unavailable] org.eclipse.core.launcher.Main.basicRun(java.lang.String[]) line: 247 org.eclipse.core.launcher.Main.run(java.lang.String[]) line: 703 org.eclipse.core.launcher.Main.main(java.lang.String[]) line: 539
org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/AddGetterSetterAction.java
}
	
	private void run(IType type, IField[] preselected, boolean editor) throws CoreException {
		if (!ElementValidator.check(type, getShell(), dialogTitle, editor))
			return;
		
		CodeGenerationSettings settings= JavaPreferencesSettings.getCodeGenerationSettings();
		ILabelProvider lp= new AddGetterSetterLabelProvider();
		Map entries= createGetterSetterMapping(type, settings);
		if (entries.isEmpty()){
			MessageDialog.openInformation(getShell(), dialogTitle, ActionMessages.getString("AddGettSetterAction.typeContainsNoFields.message")); 
			return;
		}	
		ITreeContentProvider cp= new AddGetterSetterContentProvider(entries);
		CheckedTreeSelectionDialog dialog= new CheckedTreeSelectionDialog(getShell(), lp, cp);
		dialog.setSorter(new JavaElementSorter());
		dialog.setTitle(dialogTitle);
		String message= ActionMessages.getFormattedString("AddGetterSetterAction.dialog.title", JavaElementUtil.createSignature(type));
		dialog.setMessage(message);
		dialog.setValidator(createValidator());
		dialog.setContainerMode(true);
		dialog.setSize(60, 18);
		dialog.setInput(type);
		dialog.setExpandedElements(type.getFields());
		dialog.setInitialSelections(preselected);
		dialog.open();
		Object[] result= dialog.getResult();
		if (result == null)
			return;
		IField[] getterFields= getGetterFields(result);