Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 242815

Summary: [ActivityMgmt] NPE thrown whenever context menu is being brought up
Product: [Eclipse Project] Platform Reporter: Samantha Chan <chanskw>
Component: UIAssignee: Kim Horne <eclipse>
Status: RESOLVED DUPLICATE QA Contact:
Severity: major    
Priority: P3 CC: remy.suen, valentinbaciu
Version: 3.4   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description Samantha Chan CLA 2008-07-31 23:07:43 EDT
Steps to reproduce:

From any view, select an item and right mouse click quickly. None of the icons from the context menu actions will show up.  In addition, when the context menu is in that state, none of the actions from the context menu work. 

I looked at the log, every time the context menu is brought up, a NPE is logged.  This looks like a general workbench error, and I can reproduce this error easily from any view. 

Please note that I can only reproduce this problem in our product, and not base Eclipse, so our product could have something to do with exposing this NPE.



In the removeIdentifierListener(IIdentifierListenerListener) method, here's how the code is written:

    public void removeIdentifierListener(IIdentifierListener identifierListener) {
        if (identifierListener == null) {
			throw new NullPointerException();
		}

        if (identifierListeners != null) {
			identifierListeners.remove(identifierListener);
		}

        if (identifierListeners.isEmpty()) {  // NPE HAPPENS HERE
			strongReferences.remove(this);
		}
    }


I think the logic in this method is incorrect.  The NPE happens when the Identifier checks if its identifierListeners list is empty.  However, it also checks if the identifierListeners list is null just a few lines above that.  If identifierListeners is null, then a NPE will be thrown.

Error 
Wed Jul 30 13:29:45 EDT 2008 
Unhandled event loop exception 

org.eclipse.swt.SWTException: Failed to execute runnable (java.lang.NullPointerException) 
      at org.eclipse.swt.SWT.error(Unknown Source) 
      at org.eclipse.swt.SWT.error(Unknown Source) 
      at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Unknown Source) 
      at org.eclipse.swt.widgets.Display.runAsyncMessages(Unknown Source) 
      at org.eclipse.swt.widgets.Display.readAndDispatch(Unknown Source) 
      at org.eclipse.ui.internal.Workbench.runEventLoop(Unknown Source) 
      at org.eclipse.ui.internal.Workbench.runUI(Unknown Source) 
      at org.eclipse.ui.internal.Workbench.access$4(Unknown Source) 
      at org.eclipse.ui.internal.Workbench$5.run(Unknown Source) 
      at org.eclipse.core.databinding.observable.Realm.runWithDefault(Unknown Source) 
      at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Unknown Source) 
      at org.eclipse.ui.PlatformUI.createAndRunWorkbench(Unknown Source) 
      at org.eclipse.ui.internal.ide.application.IDEApplication.start(Unknown Source) 
      at org.eclipse.equinox.internal.app.EclipseAppHandle.run(Unknown Source) 
      at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(Unknown Source) 
      at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(Unknown Source) 
      at org.eclipse.core.runtime.adaptor.EclipseStarter.run(Unknown Source) 
      at org.eclipse.core.runtime.adaptor.EclipseStarter.run(Unknown Source) 
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
      at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) 
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) 
      at java.lang.reflect.Method.invoke(Unknown Source) 
      at org.eclipse.equinox.launcher.Main.invokeFramework(Unknown Source) 
      at org.eclipse.equinox.launcher.Main.basicRun(Unknown Source) 
      at org.eclipse.equinox.launcher.Main.run(Unknown Source) 
      at org.eclipse.equinox.launcher.Main.main(Unknown Source) 
Caused by: java.lang.NullPointerException 
      at org.eclipse.ui.internal.activities.Identifier.removeIdentifierListener(Unknown Source) 
      at org.eclipse.ui.internal.PluginActionContributionItem.unhookListeners(Unknown Source) 
      at org.eclipse.ui.internal.PluginActionContributionItem.setParent(Unknown Source) 
      at org.eclipse.jface.action.ContributionManager.itemRemoved(Unknown Source) 
      at org.eclipse.jface.action.ContributionManager.removeAll(Unknown Source) 
      at org.eclipse.ui.internal.PopupMenuExtender.cleanUpContributionCache(Unknown Source) 
      at org.eclipse.ui.internal.PopupMenuExtender.access$1(Unknown Source) 
      at org.eclipse.ui.internal.PopupMenuExtender$2.run(Unknown Source) 
      at org.eclipse.swt.widgets.RunnableLock.run(Unknown Source) 
      ... 24 more
Comment 1 Kim Horne CLA 2008-08-07 09:20:30 EDT

*** This bug has been marked as a duplicate of bug 243209 ***