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

Bug 336852

Summary: NPE while disposing Workbench
Product: [RT] RAP Reporter: Benjamin Wolff <eclipse>
Component: WorkbenchAssignee: Project Inbox <rap-inbox>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: rsternberg
Version: 1.4   
Target Milestone: 1.4 M6   
Hardware: All   
OS: All   
Whiteboard:
Attachments:
Description Flags
Proposed patch
none
Updated patch none

Description Benjamin Wolff CLA 2011-02-10 12:43:15 EST
It seems that there is a NPE when disposing the Workbench. This happens with current CVS HEAD and M5 release.

Reproduce:

- Start the RAP Workbench Demo from the IDE
- Go to the console in the IDE and type "close" to shutdown the application
- Observe the NPE

I'm getting this error:

2011-02-10 18:39:31.577:WARN:/:ERROR:  Exception while disposing shell: Shell {RAP Workbench Demo}
java.lang.NullPointerException
	at org.eclipse.core.internal.runtime.InternalPlatform.getLog(InternalPlatform.java:414)
	at org.eclipse.core.runtime.Plugin.getLog(Plugin.java:291)
	at org.eclipse.ui.internal.WorkbenchPlugin.log(WorkbenchPlugin.java:936)
	at org.eclipse.ui.internal.WorkbenchPartReference$1.widgetDisposed(WorkbenchPartReference.java:172)
	at org.eclipse.swt.events.DisposeEvent.dispatchToObserver(DisposeEvent.java:64)
	at org.eclipse.rwt.internal.events.Event.processEvent(Event.java:44)
	at org.eclipse.swt.events.TypedEvent.processEvent(TypedEvent.java:163)
	at org.eclipse.swt.widgets.Widget.dispose(Widget.java:771)
	at org.eclipse.swt.widgets.Composite.releaseChildren(Composite.java:819)
	at org.eclipse.swt.widgets.Widget.dispose(Widget.java:773)
	at org.eclipse.swt.widgets.Composite.releaseChildren(Composite.java:819)
	at org.eclipse.swt.widgets.Widget.dispose(Widget.java:773)
	at org.eclipse.swt.widgets.Composite.releaseChildren(Composite.java:819)
	at org.eclipse.swt.widgets.Shell.releaseChildren(Shell.java:1068)
	at org.eclipse.swt.widgets.Widget.dispose(Widget.java:773)
	at org.eclipse.swt.widgets.Display.disposeShells(Display.java:724)
	at org.eclipse.swt.widgets.Display.release(Display.java:690)
	at org.eclipse.swt.graphics.Device.dispose(Device.java:282)
	at org.eclipse.rwt.internal.lifecycle.UIThread.processShutdown(UIThread.java:159)
	at org.eclipse.rwt.internal.lifecycle.RWTLifeCycle$UIThreadController.run(RWTLifeCycle.java:125)
	at java.lang.Thread.run(Thread.java:662)
	at org.eclipse.rwt.internal.lifecycle.UIThread.run(UIThread.java:102)
Comment 1 Ivan Furnadjiev CLA 2011-02-10 13:13:36 EST
Following your steps to reproduce with the RAP Workbench Demo, I didn't get a NPE, but a ISE (CVS HEAD):
-----------------
osgi> close

2011-02-10 20:11:13.602:WARN:/:ERROR:  Exception while executing dispose-listener.
java.lang.IllegalStateException: The service has been unregistered
	at org.eclipse.osgi.internal.serviceregistry.ServiceRegistrationImpl.unregister(ServiceRegistrationImpl.java:209)
	at org.eclipse.ui.internal.Workbench.shutdown(Workbench.java:3085)
	at org.eclipse.ui.internal.Workbench.busyClose(Workbench.java:1161)
	at org.eclipse.ui.internal.Workbench.access$12(Workbench.java:1072)
	at org.eclipse.ui.internal.Workbench$22.run(Workbench.java:1338)
	at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:66)
	at org.eclipse.ui.internal.Workbench.close(Workbench.java:1336)
	at org.eclipse.ui.internal.Workbench.close(Workbench.java:1298)
	at org.eclipse.ui.internal.Workbench$ShutdownHandler.handleEvent(Workbench.java:388)
	at org.eclipse.swt.widgets.Display.sendDisposeEvent(Display.java:710)
	at org.eclipse.swt.widgets.Display.release(Display.java:689)
	at org.eclipse.swt.graphics.Device.dispose(Device.java:282)
	at org.eclipse.rwt.internal.lifecycle.UIThread.processShutdown(UIThread.java:159)
	at org.eclipse.rwt.internal.lifecycle.RWTLifeCycle$UIThreadController.run(RWTLifeCycle.java:125)
	at java.lang.Thread.run(Thread.java:662)
	at org.eclipse.rwt.internal.lifecycle.UIThread.run(UIThread.java:102)
Comment 2 Benjamin Wolff CLA 2011-02-10 13:21:34 EST
Hi Ivan,

yes, the unregistered service error also happens occasionally, but i could not reproduce it everytime. Maybe we should further investigate this in another bug?!

It is odd that you don't get the NPE. Let me try to describe my setup so that we can exclude different setups.

I'm using the M5 target platform and the org.eclipse.rap.demo plug-in from CVS HEAD. No changes to it, CVS says it is in sync.

I run the /org.eclipse.rap.demo/launch/RAP Workbench Demo.launch configuration.

After the demo has started i type "close" to shutdown the osgi instance gracefully and this reproduces the NPE every time...
Comment 3 Ivan Furnadjiev CLA 2011-02-10 13:32:41 EST
Yes... same setup, but I'm getting all the time ISE exception from comment #1. No NPE. I'm using Helios SR1 if it matters.
Comment 4 Benjamin Wolff CLA 2011-02-10 13:38:59 EST
I'm using Helios SR1 on Ubuntu 10.10 with Sun JDK 1.6.0_22.
Just to be sure, the launch configurations are referencing the other RAP plug-ins from the target platform, not the ones from the CVS in the workspace...

At least you seem to be able to reliably reproduce the ISE. Will you open a new bug for that?
Comment 5 Ivan Furnadjiev CLA 2011-02-10 14:20:51 EST
Yes... the launch configurations are untouched from CVS, pointing to the target platform bundles. There is no change, if I'm using the bundles from the target platform (M5) or from CVS HEAD - same ISE. Ralf, can you check it on your Ubuntu? I'm testing it on Windows.
Comment 6 Ralf Sternberg CLA 2011-02-10 17:00:06 EST
(In reply to comment #5)
> Ralf, can you check it on your Ubuntu? I'm testing it on Windows.

I get the same NPE as described in the bug description.
Comment 7 Ivan Furnadjiev CLA 2011-02-11 04:44:16 EST
OK... After Eclipse restart today, I started to get a NPE as well.
Comment 8 Ivan Furnadjiev CLA 2011-02-14 02:52:05 EST
Created attachment 188872 [details]
Proposed patch

The reason for this NPE is the WorkbenchPartReference#prematureDisposeListener. As the comment states:
---
// Add a dispose listener to the part. This dispose listener does nothing but log an exception
// if the part's widgets get disposed unexpectedly. The workbench part reference is the only
// object that should dispose this control, and it will remove the listener before it does so.
---
this listener do nothing, but throws RuntimeException if part control is disposed from other place than the part itself. In our case (call "close" in osgi console), we got UIThreadTerminatedError first, which dispose the display and all other widgets and hit this dispose listener. But... the platform bundle has been stopped already. One possible solution is to check if platform is running, before throw the error (see attached patch).
Comment 9 Ivan Furnadjiev CLA 2011-02-14 02:55:24 EST
Created attachment 188873 [details]
Updated patch

Added // RAP comment to the previous patch.
Comment 10 Ivan Furnadjiev CLA 2011-02-14 03:07:21 EST
I think that which exception will you get depends on the order in which the osgi framework stops the bundles. On Friday, almost all day, I got NPE. Today, for several hours, I got ISE.
Comment 11 Ivan Furnadjiev CLA 2011-02-14 05:24:03 EST
Applied patch to CVS HEAD.
Comment 12 Benjamin Wolff CLA 2011-04-11 13:48:57 EDT
I'm still getting an NPE while shutting down the application. This time it seems to be related to ScopedPreferenceStore according to the stacktrace.
I'm using the PreferenceStore (Session and Application scope) but I don't do anything special with it when shutting down...

2011-04-11 19:45:34.281:WARN:/:ERROR:  Exception while disposing shell: Shell {AzubiDB}
java.lang.NullPointerException
	at org.eclipse.ui.preferences.ScopedPreferenceStoreCore.disposePreferenceStoreListener(ScopedPreferenceStoreCore.java:821)
	at org.eclipse.ui.preferences.ScopedPreferenceStoreCore.removePropertyChangeListener(ScopedPreferenceStoreCore.java:570)
	at org.eclipse.ui.preferences.ScopedPreferenceStore.removePropertyChangeListener(ScopedPreferenceStore.java:676)
	at org.eclipse.ui.internal.preferences.PreferenceStoreAdapter.detachListener(PreferenceStoreAdapter.java:46)
	at org.eclipse.ui.internal.preferences.PropertyMapAdapter.dispose(PropertyMapAdapter.java:59)
	at org.eclipse.ui.internal.presentations.util.TabbedStackPresentation.presentationDisposed(TabbedStackPresentation.java:352)
	at org.eclipse.ui.internal.presentations.util.TabbedStackPresentation.access$3(TabbedStackPresentation.java:351)
	at org.eclipse.ui.internal.presentations.util.TabbedStackPresentation$2.widgetDisposed(TabbedStackPresentation.java:195)
	at org.eclipse.swt.events.DisposeEvent.dispatchToObserver(DisposeEvent.java:64)
	at org.eclipse.rwt.internal.events.Event.processEvent(Event.java:44)
	at org.eclipse.swt.events.TypedEvent.processEvent(TypedEvent.java:163)
	at org.eclipse.swt.widgets.Widget.dispose(Widget.java:771)
	at org.eclipse.swt.widgets.Composite.releaseChildren(Composite.java:820)
	at org.eclipse.swt.widgets.Widget.dispose(Widget.java:773)
	at org.eclipse.swt.widgets.Composite.releaseChildren(Composite.java:820)
	at org.eclipse.swt.widgets.Widget.dispose(Widget.java:773)
	at org.eclipse.swt.widgets.Composite.releaseChildren(Composite.java:820)
	at org.eclipse.swt.widgets.Widget.dispose(Widget.java:773)
	at org.eclipse.swt.widgets.Composite.releaseChildren(Composite.java:820)
	at org.eclipse.swt.widgets.Shell.releaseChildren(Shell.java:1089)
	at org.eclipse.swt.widgets.Widget.dispose(Widget.java:773)
	at org.eclipse.swt.widgets.Display.disposeShells(Display.java:724)
	at org.eclipse.swt.widgets.Display.release(Display.java:690)
	at org.eclipse.swt.graphics.Device.dispose(Device.java:282)
	at de.ineos.azubidb.Application.start(Application.java:32)
	at org.eclipse.rap.ui.internal.application.EntrypointApplicationWrapper.createUI(EntrypointApplicationWrapper.java:27)
	at org.eclipse.rwt.internal.lifecycle.EntryPointManagerInstance.createUI(EntryPointManagerInstance.java:79)
	at org.eclipse.rwt.internal.lifecycle.EntryPointManager.createUI(EntryPointManager.java:33)
	at org.eclipse.rwt.internal.lifecycle.RWTLifeCycle.createUI(RWTLifeCycle.java:242)
	at org.eclipse.rwt.internal.lifecycle.RWTLifeCycle$UIThreadController.run(RWTLifeCycle.java:111)
	at java.lang.Thread.run(Thread.java:662)
	at org.eclipse.rwt.internal.lifecycle.UIThread.run(UIThread.java:102)
Comment 13 Ivan Furnadjiev CLA 2011-04-11 14:21:56 EDT
Ben, would you mind to open a separate bug for this NPE as this is a completely different NPE from the original one in this bug. As I can't reproduce it with the Workbench Demo, please attach a snippet to reproduce it to the new bug . Thanks.
Comment 14 Benjamin Wolff CLA 2011-04-12 05:23:04 EDT
Done!

https://bugs.eclipse.org/bugs/show_bug.cgi?id=342527