Community
Participate
Working Groups
Build Identifier: M20100909-0800 NewProjectCreationOperation cannot be executed in a non UI thread because openFile(IFile) calls PDEPlugin.getActiveWorkbenchWindow() which returns null when invoked from a non UI thread. Please see the current code fragment of NewProjectCreationOperation that comes with Eclipse 3.6.1: private void openFile(final IFile file) { final IWorkbenchWindow ww = PDEPlugin.getActiveWorkbenchWindow(); final IWorkbenchPage page = ww.getActivePage(); if (page == null) return; final IWorkbenchPart focusPart = page.getActivePart(); ww.getShell().getDisplay().asyncExec(new Runnable() { public void run() { if (focusPart instanceof ISetSelectionTarget) { ISelection selection = new StructuredSelectionfile); ((ISetSelectionTarget) focusPart).selectReveal(selection); } try { IDE.openEditor(page, file, true); } catch (PartInitException e) { } } }); } The implementation of openFile(IFile) should be changed as shown below: private void openFile(final IFile file) { PDEPlugin.getDefault().getWorkbench().getDisplay().asyncExec(new Runnable() { public void run() { final IWorkbenchWindow ww = PDEPlugin.getActiveWorkbenchWindow(); final IWorkbenchPage page = ww.getActivePage(); if (page == null) return; final IWorkbenchPart focusPart = page.getActivePart(); if (focusPart instanceof ISetSelectionTarget) { ISelection selection = new StructuredSelectionfile); ((ISetSelectionTarget) focusPart).selectReveal(selection); } try { IDE.openEditor(page, file, true); } catch (PartInitException e) { } } }); } Reproducible: Always Steps to Reproduce: as mentioned above
Note that NewProjectCreationOperation is an internal UI class. There has been interest in making it api, but the work never materialized. How the job works may change between releases. Is this NPE the only issue preventing you from using the job in a non-UI thread?
Yes, it's the only issue. Only care must be taken when implementing IProjectProvider. The IProjectProvider's methods must also run in UI thread. It would be nice if NewProjectCreationOperation could consider this.
Fixed in HEAD. See PDEPlugin and NewProjectCreationOperation.
Fixed.