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

Bug 531241

Summary: ConsoleDropDownAction and OpenConsoleAction disposed on perspective reset
Product: [Eclipse Project] Platform Reporter: Jonathan Williams <jonwilliams>
Component: DebugAssignee: Andrey Loskutov <loskutov>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: loskutov, sarika.sinha
Version: 4.5.2   
Target Milestone: 4.8 M6   
Hardware: PC   
OS: All   
See Also: https://git.eclipse.org/r/117600
https://git.eclipse.org/c/platform/eclipse.platform.debug.git/commit/?id=d1f97f64e7962451e851095d52726adbbc861cf4
Whiteboard:

Description Jonathan Williams CLA 2018-02-15 18:35:19 EST
There is a bug involving the Console View and resetting the perspective. 

If you interact with the 'Display Selected Console' drop down, and then immediately reset your perspective, subsequent attempts to interact with the Display Selected Console dropdown result in no dropdown displaying and the following stack trace appearing in the logs.

!ENTRY org.eclipse.ui 4 0 2018-02-15 17:30:08.137
!MESSAGE Unhandled event loop exception
!STACK 0
java.lang.NullPointerException
	at org.eclipse.ui.internal.console.ConsoleDropDownAction.getMenu(ConsoleDropDownAction.java:92)
	at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:513)
	at org.eclipse.jface.action.ActionContributionItem.lambda$5(ActionContributionItem.java:436)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:86)
	at org.eclipse.swt.widgets.Display.sendEvent(Display.java:5268)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1348)
	at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4522)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:4107)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$5.run(PartRenderingEngine.java:1150)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:336)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1039)
	at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:153)
	at org.eclipse.ui.internal.Workbench.lambda$3(Workbench.java:680)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:336)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:594)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:148)
	at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:151)
	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:134)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:388)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:243)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:653)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:590)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1499)
	at org.eclipse.equinox.launcher.Main.main(Main.java:1472)

Most perspectives seem to exhibit this behavior, with the exception of the Debug perspective. Debugging into the problem, it appears that the ConsoleDropDownAction for the Display Selected Console action is getting disposed by the perspective reset.

Version info:
Eclipse IDE for Eclipse Committers

Version: Oxygen.2 Release (4.7.2)
Build id: 20171218-0600

OS: Ubuntu 16.04
Comment 1 Jonathan Williams CLA 2018-02-15 18:40:56 EST
I am able to cause a similar behavior to occur with the Open Console drop down menu as well.

!ENTRY org.eclipse.ui 4 0 2018-02-15 18:39:22.554
!MESSAGE Unhandled event loop exception
!STACK 0
java.lang.NullPointerException
	at org.eclipse.ui.internal.console.OpenConsoleAction.getMenu(OpenConsoleAction.java:84)
	at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:513)
	at org.eclipse.jface.action.ActionContributionItem.lambda$5(ActionContributionItem.java:436)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:86)
	at org.eclipse.swt.widgets.Display.sendEvent(Display.java:5268)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1348)
	at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4522)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:4107)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$5.run(PartRenderingEngine.java:1150)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:336)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1039)
	at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:153)
	at org.eclipse.ui.internal.Workbench.lambda$3(Workbench.java:680)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:336)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:594)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:148)
	at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:151)
	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:134)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:388)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:243)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:653)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:590)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1499)
	at org.eclipse.equinox.launcher.Main.main(Main.java:1472)
Comment 2 Jonathan Williams CLA 2018-02-16 13:57:31 EST
Workaround: You can access the dropdown menus again from a new Console View.
Comment 3 Andrey Loskutov CLA 2018-02-18 03:41:40 EST
Interesting, probably there since 3.x or at least since very beginning of 4.x.

The *right* steps to reproduce:
1) Start with fresh SDK workspace (usually Java perspective without Console is shown)
2) Open Debug perspective (Console view is opened)
3) Open new Java Console and new OSGI Console (so that "Display selected console is enabled")
4) Click on "Display Selected" drop-down to see two consoles in the menu
5) Switch to Java perspective, open Console view
6) Reset Java perspective (Console view is closed)
7) Switch to Debug perspective and try to use both drop-down buttons => kaboom.

The problem is that ConsoleDropDownAction and OpenConsoleAction created for both drop-down menus are disposed during Java perspective reset so that they will fail later to create menus if asked in Debug perspective.

The reason is the code in org.eclipse.jface.action.ActionContributionItem.handleWidgetDispose(Event). It tries to dispose menus from drop-down contributions (that is probably OK) BUT also it tries to dispose the creators of those menus too. In our case this results in the disposing of the ConsoleDropDownAction and OpenConsoleAction still referenced in the Console view shown in another perspective :-(

See the two stacks below.

java.lang.NullPointerException
	at org.eclipse.ui.internal.console.OpenConsoleAction.getMenu(OpenConsoleAction.java:98)
	at org.eclipse.ui.internal.console.OpenConsoleAction.runWithEvent(OpenConsoleAction.java:81)
	at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:565)
	at org.eclipse.jface.action.ActionContributionItem.lambda$5(ActionContributionItem.java:436)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:86)

java.lang.NullPointerException
	at org.eclipse.ui.internal.console.ConsoleDropDownAction.getMenu(ConsoleDropDownAction.java:80)
	at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:513)
	at org.eclipse.jface.action.ActionContributionItem.lambda$5(ActionContributionItem.java:436)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:86)
Comment 4 Eclipse Genie CLA 2018-02-18 04:38:43 EST
New Gerrit change created: https://git.eclipse.org/r/117600
Comment 5 Andrey Loskutov CLA 2018-02-18 04:39:44 EST
I have a patch, but it need to be tested for possible menu contributions leakage / other unexpected side effects.
Comment 7 Andrey Loskutov CLA 2018-02-18 10:11:44 EST
3.8 doesn't have the problem, but 4.5.2 has (I have no older 4.x instances right now to test).
Comment 8 Andrey Loskutov CLA 2018-02-18 10:14:41 EST
Just for the record, there were 203 reporters in Aeri for that: https://dev.eclipse.org/recommenders/committers/aeri/v2/#!/problems/5522d3e4e4b026254ee016f3
Comment 9 Sarika Sinha CLA 2018-03-07 04:05:27 EST
Eclipse SDK

Version: Photon (4.8)
Build id: I20180306-2000