Project: JDT
Bug 31687 NPE in FindOccurrencesEngine.create
Reported: 2003-02-12 12:48:53 | Status: resolved fixed

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

Files changed in fix:
org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/AddImportOnSelectionAction.java org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/AddDelegateMethodsAction.java org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/AddGetterSetterAction.java org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/FindOccurrencesInFileAction.java org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/InlineAction.java org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/JavaSearchActionGroup.java org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/OrganizeImportsAction.java