Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 364848 - [Compatibility] NPE trying to retrieve undo context
Summary: [Compatibility] NPE trying to retrieve undo context
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.1   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: 4.2 M4   Edit
Assignee: Paul Webster CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-11-25 10:29 EST by Olivier Thomann CLA
Modified: 2011-12-08 08:20 EST (History)
4 users (show)

See Also:


Attachments
WorkbenchAdapterFactory patch v1 (793 bytes, patch)
2011-12-01 16:12 EST, Remy Suen CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Olivier Thomann CLA 2011-11-25 10:29:35 EST
Using I20111116-0810 (4.2 I-build), I get this error almost on every restart.

org.osgi.framework.BundleException: Exception in org.eclipse.ltk.internal.core.refactoring.RefactoringCorePlugin.stop() of bundle org.eclipse.ltk.core.refactoring.
	at org.eclipse.osgi.framework.internal.core.BundleContextImpl.stop(BundleContextImpl.java:791)
	at org.eclipse.osgi.framework.internal.core.BundleHost.stopWorker(BundleHost.java:510)
	at org.eclipse.osgi.framework.internal.core.AbstractBundle.suspend(AbstractBundle.java:566)
	at org.eclipse.osgi.framework.internal.core.Framework.suspendBundle(Framework.java:1207)
	at org.eclipse.osgi.framework.internal.core.StartLevelManager.decFWSL(StartLevelManager.java:592)
	at org.eclipse.osgi.framework.internal.core.StartLevelManager.doSetStartLevel(StartLevelManager.java:257)
	at org.eclipse.osgi.framework.internal.core.StartLevelManager.shutdown(StartLevelManager.java:215)
	at org.eclipse.osgi.framework.internal.core.InternalSystemBundle.suspend(InternalSystemBundle.java:284)
	at org.eclipse.osgi.framework.internal.core.Framework.shutdown(Framework.java:693)
	at org.eclipse.osgi.framework.internal.core.Framework.close(Framework.java:600)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.shutdown(EclipseStarter.java:398)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:198)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:624)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:579)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1433)
	at org.eclipse.equinox.launcher.Main.main(Main.java:1409)
Caused by: java.lang.NullPointerException
	at org.eclipse.ui.internal.ide.model.WorkbenchAdapterFactory.getUndoContext(WorkbenchAdapterFactory.java:188)
	at org.eclipse.ui.internal.ide.model.WorkbenchAdapterFactory.getAdapter(WorkbenchAdapterFactory.java:102)
	at org.eclipse.core.internal.runtime.AdapterManager.getAdapter(AdapterManager.java:295)
	at org.eclipse.core.runtime.PlatformObject.getAdapter(PlatformObject.java:66)
	at org.eclipse.ltk.internal.core.refactoring.RefactoringCorePlugin.stop(RefactoringCorePlugin.java:124)
	at org.eclipse.osgi.framework.internal.core.BundleContextImpl$2.run(BundleContextImpl.java:771)
	at java.security.AccessController.doPrivileged(Native Method)
	at org.eclipse.osgi.framework.internal.core.BundleContextImpl.stop(BundleContextImpl.java:764)
	... 19 more
Root exception:
java.lang.NullPointerException
	at org.eclipse.ui.internal.ide.model.WorkbenchAdapterFactory.getUndoContext(WorkbenchAdapterFactory.java:188)
	at org.eclipse.ui.internal.ide.model.WorkbenchAdapterFactory.getAdapter(WorkbenchAdapterFactory.java:102)
	at org.eclipse.core.internal.runtime.AdapterManager.getAdapter(AdapterManager.java:295)
	at org.eclipse.core.runtime.PlatformObject.getAdapter(PlatformObject.java:66)
	at org.eclipse.ltk.internal.core.refactoring.RefactoringCorePlugin.stop(RefactoringCorePlugin.java:124)
	at org.eclipse.osgi.framework.internal.core.BundleContextImpl$2.run(BundleContextImpl.java:771)
	at java.security.AccessController.doPrivileged(Native Method)
	at org.eclipse.osgi.framework.internal.core.BundleContextImpl.stop(BundleContextImpl.java:764)
	at org.eclipse.osgi.framework.internal.core.BundleHost.stopWorker(BundleHost.java:510)
	at org.eclipse.osgi.framework.internal.core.AbstractBundle.suspend(AbstractBundle.java:566)
	at org.eclipse.osgi.framework.internal.core.Framework.suspendBundle(Framework.java:1207)
	at org.eclipse.osgi.framework.internal.core.StartLevelManager.decFWSL(StartLevelManager.java:592)
	at org.eclipse.osgi.framework.internal.core.StartLevelManager.doSetStartLevel(StartLevelManager.java:257)
	at org.eclipse.osgi.framework.internal.core.StartLevelManager.shutdown(StartLevelManager.java:215)
	at org.eclipse.osgi.framework.internal.core.InternalSystemBundle.suspend(InternalSystemBundle.java:284)
	at org.eclipse.osgi.framework.internal.core.Framework.shutdown(Framework.java:693)
	at org.eclipse.osgi.framework.internal.core.Framework.close(Framework.java:600)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.shutdown(EclipseStarter.java:398)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:198)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:624)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:579)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1433)
	at org.eclipse.equinox.launcher.Main.main(Main.java:1409)
Comment 1 Remy Suen CLA 2011-11-28 07:53:32 EST
I found this in my error log also on I20111124-2200.
Comment 2 Remy Suen CLA 2011-12-01 13:11:54 EST
WorkbenchPlugin's getOperationSupport() is returning null. The application context appears to have been disposed at this point.
Comment 3 Remy Suen CLA 2011-12-01 14:06:09 EST
Interestingly enough, it is also null in 3.x as the workbench bundle has already shutdown. However, the code path is different there so a new instance is just spawned at will.

public IWorkbenchOperationSupport getOperationSupport() {
  if (operationSupport == null) {
    operationSupport = new WorkbenchOperationSupport();
  }
  return operationSupport;
}
Comment 4 Remy Suen CLA 2011-12-01 14:48:01 EST
This bug appears to have manifested itself because of the changes for bug 317706.

I don't see any problems if I use 5ac37d109d815c15a42bf8b626b87870570533e1.
Comment 5 Remy Suen CLA 2011-12-01 16:12:31 EST
Created attachment 207813 [details]
WorkbenchAdapterFactory patch v1

We could just return 'null' if the workbench is closing.
Comment 6 Remy Suen CLA 2011-12-01 16:14:33 EST
getOperationSupport() is not spec'd to return null although it's not clear to me what our general contract is for returning stuff when the workbench is shutting down or the bundle has already been stopped. Is attachment 207813 [details] acceptable or do we need to do something deeper?
Comment 7 Paul Webster CLA 2011-12-05 15:51:08 EST
(In reply to comment #5)
> Created attachment 207813 [details]
> WorkbenchAdapterFactory patch v1
> 

I've released this to master for 4.2.  We will monitor the situation closely tomorrow.

PW
Comment 8 Dani Megert CLA 2011-12-06 08:42:59 EST
(In reply to comment #3)
> Interestingly enough, it is also null in 3.x as the workbench bundle has
> already shutdown. However, the code path is different there so a new instance
> is just spawned at will.
> 
> public IWorkbenchOperationSupport getOperationSupport() {
>   if (operationSupport == null) {
>     operationSupport = new WorkbenchOperationSupport();
>   }
>   return operationSupport;
> }

Yes, this is because the API in 'IWorkbench' does not specify/allow that 'null' can be returned. Therefore the WorkbenchPlugin getters in 3.x use the above pattern. Either the 4.x code is fixed accordingly or the Javadoc in 4.x needs to be updated - of course with the risk of getting NPEs like the one reported here.

Looking at the fix, I'm not 100% that
    !isClosing() ==> PlatformUI.getWorkbench().getOperationSupport() != null
hence, I would get the operation support and check it for 'null'.
Comment 9 Paul Webster CLA 2011-12-07 19:37:39 EST
(In reply to comment #8)
> Looking at the fix, I'm not 100% that
>     !isClosing() ==> PlatformUI.getWorkbench().getOperationSupport() != null
> hence, I would get the operation support and check it for 'null'.

right.  I think Remy and I should either revert this fix or provide a new fix (even similar to the current one, were we return a bogus support if it's not in the e4Context).  That will match the existing behaviour.

PW
Comment 10 Paul Webster CLA 2011-12-08 08:20:31 EST
Fix released to 4.2 and IDE change reverted in 3.8
PW