Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 328977 - NewProjectCreationOperation: NPE when executing in non UI thread
Summary: NewProjectCreationOperation: NPE when executing in non UI thread
Status: RESOLVED FIXED
Alias: None
Product: PDE
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.7   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 3.7 M7   Edit
Assignee: Curtis Windatt CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-10-28 16:22 EDT by Gerhard Leonhartsberger CLA
Modified: 2011-03-14 17:03 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Gerhard Leonhartsberger CLA 2010-10-28 16:22:53 EDT
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
Comment 1 Curtis Windatt CLA 2010-10-29 10:48:31 EDT
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?
Comment 2 Gerhard Leonhartsberger CLA 2010-10-29 11:02:46 EDT
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.
Comment 3 Curtis Windatt CLA 2011-03-14 17:03:08 EDT
Fixed in HEAD.  See PDEPlugin and NewProjectCreationOperation.
Comment 4 Curtis Windatt CLA 2011-03-14 17:03:22 EDT
Fixed.