Bug 204192 - [WorkbenchParts] NullPointerException in WorkbenchWindow.hardClose
Summary: [WorkbenchParts] NullPointerException in WorkbenchWindow.hardClose
Status: VERIFIED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.3   Edit
Hardware: PC Windows Vista
: P3 normal (vote)
Target Milestone: 4.2 M7   Edit
Assignee: Oleg Besedin CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 345600 (view as bug list)
Depends on:
Blocks:
 
Reported: 2007-09-20 17:14 EDT by Kris Klindworth CLA
Modified: 2014-10-13 08:36 EDT (History)
4 users (show)

See Also:


Attachments
Simple RCP app to demonstrate the NPE (8.89 KB, application/zip)
2007-09-20 17:14 EDT, Kris Klindworth CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Kris Klindworth CLA 2007-09-20 17:14:02 EDT
Created attachment 78895 [details]
Simple RCP app to demonstrate the NPE

Build ID: I20070621-1340

I've attached a simple RCP app to demonstrate the issue. 

I'm attaching a window listener to the workbench to close all workbench windows when the first window is closed.  

Steps To Reproduce:
1. Run the app and open a few windows by clicking the "Open window" button.
2. Close the window that was first opened when the app started via the X in the right hand corner.
3. All of the windows close correctly, and then the workbench is closed, but the following appears in the log:

java.lang.NullPointerException
	at org.eclipse.ui.internal.WorkbenchWindow.hardClose(WorkbenchWindow.java:1567)
	at org.eclipse.ui.internal.WorkbenchWindow.busyClose(WorkbenchWindow.java:699)
	at org.eclipse.ui.internal.WorkbenchWindow.access$0(WorkbenchWindow.java:675)
	at org.eclipse.ui.internal.WorkbenchWindow$2.run(WorkbenchWindow.java:790)
	at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:67)
	at org.eclipse.ui.internal.WorkbenchWindow.close(WorkbenchWindow.java:788)
	at org.eclipse.jface.window.Window.handleShellCloseEvent(Window.java:736)
	at org.eclipse.jface.window.Window$3.shellClosed(Window.java:682)
	at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:91)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:66)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:938)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:962)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:947)
	at org.eclipse.swt.widgets.Decorations.closeWidget(Decorations.java:301)
	at org.eclipse.swt.widgets.Decorations.WM_CLOSE(Decorations.java:1651)
	at org.eclipse.swt.widgets.Control.windowProc(Control.java:3674)
	at org.eclipse.swt.widgets.Canvas.windowProc(Canvas.java:291)
	at org.eclipse.swt.widgets.Decorations.windowProc(Decorations.java:1584)
	at org.eclipse.swt.widgets.Shell.windowProc(Shell.java:1753)
	at org.eclipse.swt.widgets.Display.windowProc(Display.java:4351)
	at org.eclipse.swt.internal.win32.OS.DefWindowProcW(Native Method)
	at org.eclipse.swt.internal.win32.OS.DefWindowProc(OS.java:2259)
	at org.eclipse.swt.widgets.Shell.callWindowProc(Shell.java:456)
	at org.eclipse.swt.widgets.Control.windowProc(Control.java:3760)
	at org.eclipse.swt.widgets.Canvas.windowProc(Canvas.java:291)
	at org.eclipse.swt.widgets.Decorations.windowProc(Decorations.java:1584)
	at org.eclipse.swt.widgets.Shell.windowProc(Shell.java:1753)
	at org.eclipse.swt.widgets.Display.windowProc(Display.java:4351)
	at org.eclipse.swt.internal.win32.OS.DefWindowProcW(Native Method)
	at org.eclipse.swt.internal.win32.OS.DefWindowProc(OS.java:2259)
	at org.eclipse.swt.widgets.Shell.callWindowProc(Shell.java:456)
	at org.eclipse.swt.widgets.Control.windowProc(Control.java:3760)
	at org.eclipse.swt.widgets.Canvas.windowProc(Canvas.java:291)
	at org.eclipse.swt.widgets.Decorations.windowProc(Decorations.java:1584)
	at org.eclipse.swt.widgets.Shell.windowProc(Shell.java:1753)
	at org.eclipse.swt.widgets.Display.windowProc(Display.java:4351)
	at org.eclipse.swt.internal.win32.OS.DispatchMessageW(Native Method)
	at org.eclipse.swt.internal.win32.OS.DispatchMessage(OS.java:2264)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3291)
	at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2389)
	at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2353)
	at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2219)
	at org.eclipse.ui.internal.Workbench$4.run(Workbench.java:466)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:289)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:461)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
	at workbenchclose.Application.start(Application.java:20)
	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:153)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:106)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:76)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:363)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:176)
	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(Main.java:504)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:443)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1169)
	at org.eclipse.equinox.launcher.Main.main(Main.java:1144)
Comment 1 Peter Larsen CLA 2011-12-05 08:33:57 EST
Found a recent bug in .log, that looks identical to this old one.

!SESSION 2011-11-15 10:39:21.037 -----------------------------------------------
eclipse.buildId=I20110613-1736
java.version=1.7.0
java.vendor=Oracle Corporation
BootLoader constants: OS=win32, ARCH=x86_64, WS=win32, NL=en_US
Framework arguments:  -product org.eclipse.epp.package.java.product
Command-line arguments:  -os win32 -ws win32 -arch x86_64 -product org.eclipse.epp.package.java.product


!ENTRY org.eclipse.ui 4 0 2011-11-22 12:51:42.740
!MESSAGE Unhandled event loop exception
!STACK 0
java.lang.NullPointerException
	at org.eclipse.ui.internal.WorkbenchWindow.hardClose(WorkbenchWindow.java:1708)
	at org.eclipse.ui.internal.WorkbenchWindow.busyClose(WorkbenchWindow.java:730)
	at org.eclipse.ui.internal.WorkbenchWindow.access$0(WorkbenchWindow.java:715)
	at org.eclipse.ui.internal.WorkbenchWindow$5.run(WorkbenchWindow.java:860)
	at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:70)
	at org.eclipse.ui.internal.WorkbenchWindow.close(WorkbenchWindow.java:858)
	at org.eclipse.jface.window.Window.handleShellCloseEvent(Window.java:741)
	at org.eclipse.jface.window.Window$3.shellClosed(Window.java:687)
	at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:98)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1077)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1062)
	at org.eclipse.swt.widgets.Decorations.closeWidget(Decorations.java:308)
	at org.eclipse.swt.widgets.Decorations.WM_CLOSE(Decorations.java:1677)
	at org.eclipse.swt.widgets.Control.windowProc(Control.java:4530)
	at org.eclipse.swt.widgets.Canvas.windowProc(Canvas.java:341)
	at org.eclipse.swt.widgets.Decorations.windowProc(Decorations.java:1610)
	at org.eclipse.swt.widgets.Shell.windowProc(Shell.java:2061)
	at org.eclipse.swt.widgets.Display.windowProc(Display.java:4972)
	at org.eclipse.swt.internal.win32.OS.DefWindowProcW(Native Method)
	at org.eclipse.swt.internal.win32.OS.DefWindowProc(OS.java:2525)
	at org.eclipse.swt.widgets.Shell.callWindowProc(Shell.java:498)
	at org.eclipse.swt.widgets.Control.windowProc(Control.java:4623)
	at org.eclipse.swt.widgets.Canvas.windowProc(Canvas.java:341)
	at org.eclipse.swt.widgets.Decorations.windowProc(Decorations.java:1610)
	at org.eclipse.swt.widgets.Shell.windowProc(Shell.java:2061)
	at org.eclipse.swt.widgets.Display.windowProc(Display.java:4985)
	at org.eclipse.swt.internal.win32.OS.DispatchMessageW(Native Method)
	at org.eclipse.swt.internal.win32.OS.DispatchMessage(OS.java:2530)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3752)
	at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2696)
	at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2660)
	at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2494)
	at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:674)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:667)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
	at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:123)
	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:344)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
	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(Main.java:622)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:577)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1410)
	at org.eclipse.equinox.launcher.Main.main(Main.java:1386)
Comment 2 Eric Moffatt CLA 2012-02-07 14:49:09 EST
The problem still exists. I had to include all the plugins in my ws in the launch config in order to get past an NPE in ModelServiceImpl's <init> where the EventBroker was null.
Comment 3 Oleg Besedin CLA 2012-04-03 16:52:51 EDT
First, thank you for supplying code to duplicate the problem!

As for the problem itself, ultimately, this is an example of plugin code doing a wrong thing. It is not being handled well by the workbench code, but still.

In the example code the workbenchclose.View class:

WindowListener#windowClosed(IWorkbenchWindow window) {
	...
	openWindows.close();
	...
}

This 
 a) causes a re-entry into the workbenh window closing routine which cases an NPE, and 
 b) removes all workbench windows from the model.

I don't mind adding a check to the UI code for NPE (and I added one, see Git references below) but the View listener code is just a wrong thing to do. If you close and restart your example application, you'll see... well, rather, you won't see anything show up as the line above closes all workbench windows. So, on restart you have an application with no windows.

Depeneding on the intentions I'd suggest:

- don't force window closing at all
- if you'd like to close "secondary" windows on shutdown so that they won't be re-opened on startup, add tags to them and make sure you only cose "secondary" windows
- if you really want to remove *all* windows from the model on shutdown, you probably will need to add a model processor to re-add a window on startup. 


Git references:

http://git.eclipse.org/c/platform/eclipse.platform.ui.git/commit/?id=2ab7f63d9dfa46b6d72c6d7a1668c400bf5fc517

http://git.eclipse.org/c/platform/eclipse.platform.ui.git/commit/?id=9846f4a0e279ec0600421d2659401f6fc44dd171
Comment 4 Oleg Besedin CLA 2012-05-01 14:42:24 EDT
Verified that there is no NPE on shutdown in I20120430-1800.

(The attached RCP app can not be restarted "as is" after shutdown as it removes all windows from the model.)
Comment 5 Arun Thondapu CLA 2014-10-13 08:36:59 EDT
*** Bug 345600 has been marked as a duplicate of this bug. ***