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

Bug 387234

Summary: Restarting wth 'closed' DW's results in the perspective being reset
Product: [Eclipse Project] Platform Reporter: Eric Moffatt <emoffatt>
Component: UIAssignee: Platform-UI-Inbox <Platform-UI-Inbox>
Status: CLOSED DUPLICATE QA Contact:
Severity: normal    
Priority: P3 CC: daniel_megert, matthias.keller, Michael_Rennie, smcclenahan, sptaszkiewicz
Version: 4.2   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard: candidate43
Attachments:
Description Flags
Patch v.0.1
none
Patch v.0.2 none

Description Eric Moffatt CLA 2012-08-14 13:51:24 EDT
To repro:

Drag the Outline view out to make a DW.
Close it using the red 'X'
Restart

You get:

Caused by: java.lang.IllegalArgumentException: The selected element org.eclipse.e4.ui.model.application.ui.basic.impl.PartStackImpl@1579371 (elementId: right, tags: [newtablook, org.eclipse.e4.secondaryNavigationStack], contributorURI: null) (widget: null, renderer: null, toBeRendered: false, onTop: false, visible: true, containerData: 2500, accessibilityPhrase: null) must be visible in the UI presentation
	at org.eclipse.e4.ui.model.application.ui.impl.ElementContainerImpl.setSelectedElement(ElementContainerImpl.java:164)

Basically, we've added a model check that prevents a modeled container from having a selected element that is not visible. This is almost certainly an activation defect (if you close the Outline view instead of using the red 'x' then all is well).
Comment 1 Szymon Ptaszkiewicz CLA 2012-12-14 10:19:26 EST
I can reproduce it. Investigating.
Comment 2 Szymon Ptaszkiewicz CLA 2012-12-14 13:37:23 EST
Exception is thrown because selectedElement is not set to null for TrimmedWindowImpl before saving workbench.xmi. You can see wrong selectedElement value in workbench.xmi so it is possible to tell when IllegalArgumentException will happen even before running Eclipse.
Comment 3 Szymon Ptaszkiewicz CLA 2012-12-17 13:07:42 EST
Created attachment 224810 [details]
Patch v.0.1

If we use the red 'x' then window is closed before the view gets closed. In such case the widget is gone before model is updated. If underlying widget is already null, we still need to run the whole update stuff to make sure model is correctly updated. Patch contains fix and test for this bug. There may be something wrong with the test because it passes if I run all tests from PartRenderingEngineTests, but fails for UIAllTests which is strange...
Comment 4 Eric Moffatt CLA 2012-12-17 14:16:49 EST
Szymon, I just tried this on XP using I20121210-2000 and it appears to work OK for me. Could you try with 4.3M4 and verify that there's still a bug here ?

I did as you suggest, dragged Outline out to make s DW then closed it with the 'x'. On a restart everything worked, the perspective was as it was when I closed (no reset) and re-opening the Outline view correctly showed it in its DW...

(I thought I'd already commented here but now suspect there's a defect with an incorrect comment on it...;-).
Comment 5 Szymon Ptaszkiewicz CLA 2012-12-18 05:42:18 EST
Thanks for quick response Eric. I just tried using I20121214-0730 (latest I-build) and it is reproducible there. There is one step missing in comment 0 which is important to reproduce the problem - after creating DW you need to click on the view to activate it. Full reproduction scenario:

1. Drag the Outline view out to make a DW.
2. Click the Outline view to activate it/set focus.
3. Close DW using the red 'X'.
4. Restart (close the main window using the red 'X').
=> IllegalArgumentException is thrown and perspective is reset.
Comment 6 Michael Rennie CLA 2013-02-11 17:12:51 EST
(In reply to comment #5)
> Thanks for quick response Eric. I just tried using I20121214-0730 (latest
> I-build) and it is reproducible there. There is one step missing in comment
> 0 which is important to reproduce the problem - after creating DW you need
> to click on the view to activate it. Full reproduction scenario:
> 
> 1. Drag the Outline view out to make a DW.
> 2. Click the Outline view to activate it/set focus.
> 3. Close DW using the red 'X'.
> 4. Restart (close the main window using the red 'X').
> => IllegalArgumentException is thrown and perspective is reset.

Just reproduced using 

Version: 4.3.0
Build id: I20130205-0800

sigh, now I have to customize my Java perspective again.

The patch does prevent the perspective from being reset, but it introduces the following:

java.lang.IllegalArgumentException: Argument cannot be null
	at org.eclipse.swt.SWT.error(SWT.java:4354)
	at org.eclipse.swt.SWT.error(SWT.java:4288)
	at org.eclipse.swt.SWT.error(SWT.java:4259)
	at org.eclipse.swt.widgets.Widget.error(Widget.java:783)
	at org.eclipse.swt.widgets.Widget.checkParent(Widget.java:510)
	at org.eclipse.swt.widgets.Widget.<init>(Widget.java:132)
	at org.eclipse.swt.widgets.Control.<init>(Control.java:116)
	at org.eclipse.swt.widgets.Scrollable.<init>(Scrollable.java:73)
	at org.eclipse.swt.widgets.Composite.<init>(Composite.java:91)
	at org.eclipse.e4.ui.workbench.renderers.swt.ElementReferenceRenderer.createWidget(ElementReferenceRenderer.java:55)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.createWidget(PartRenderingEngine.java:892)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeCreateGui(PartRenderingEngine.java:626)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeCreateGui(PartRenderingEngine.java:728)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.access$2(PartRenderingEngine.java:699)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$7.run(PartRenderingEngine.java:693)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.createGui(PartRenderingEngine.java:678)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$1.handleEvent(PartRenderingEngine.java:129)
	at org.eclipse.e4.ui.services.internal.events.UIEventHandler$1.run(UIEventHandler.java:41)
	at org.eclipse.swt.widgets.Synchronizer.syncExec(Synchronizer.java:180)
	at org.eclipse.ui.internal.UISynchronizer.syncExec(UISynchronizer.java:150)
	at org.eclipse.swt.widgets.Display.syncExec(Display.java:4628)
	at org.eclipse.e4.ui.internal.workbench.swt.E4Application$1.syncExec(E4Application.java:199)
	at org.eclipse.e4.ui.services.internal.events.UIEventHandler.handleEvent(UIEventHandler.java:38)
	at org.eclipse.equinox.internal.event.EventHandlerWrapper.handleEvent(EventHandlerWrapper.java:197)
	at org.eclipse.equinox.internal.event.EventHandlerTracker.dispatchEvent(EventHandlerTracker.java:197)
	at org.eclipse.equinox.internal.event.EventHandlerTracker.dispatchEvent(EventHandlerTracker.java:1)
	at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)
	at org.eclipse.osgi.framework.eventmgr.ListenerQueue.dispatchEventSynchronous(ListenerQueue.java:148)
	at org.eclipse.equinox.internal.event.EventAdminImpl.dispatchEvent(EventAdminImpl.java:135)
	at org.eclipse.equinox.internal.event.EventAdminImpl.sendEvent(EventAdminImpl.java:78)
	at org.eclipse.equinox.internal.event.EventComponent.sendEvent(EventComponent.java:39)
	at org.eclipse.e4.ui.services.internal.events.EventBroker.send(EventBroker.java:80)
	at org.eclipse.e4.ui.internal.workbench.UIEventPublisher.notifyChanged(UIEventPublisher.java:58)
	at org.eclipse.emf.common.notify.impl.BasicNotifierImpl.eNotify(BasicNotifierImpl.java:374)
	at org.eclipse.e4.ui.model.application.ui.impl.UIElementImpl.setToBeRendered(UIElementImpl.java:290)
	at org.eclipse.e4.ui.internal.workbench.ModelServiceImpl.showElementInWindow(ModelServiceImpl.java:420)
	at org.eclipse.e4.ui.internal.workbench.ModelServiceImpl.bringToTop(ModelServiceImpl.java:389)
	at org.eclipse.e4.ui.internal.workbench.PartServiceImpl.delegateBringToTop(PartServiceImpl.java:606)
	at org.eclipse.e4.ui.internal.workbench.PartServiceImpl.activate(PartServiceImpl.java:579)
	at org.eclipse.e4.ui.internal.workbench.PartServiceImpl.activate(PartServiceImpl.java:549)
	at org.eclipse.e4.ui.internal.workbench.PartServiceImpl.activate(PartServiceImpl.java:538)
	at org.eclipse.e4.ui.internal.workbench.PartServiceImpl.showPart(PartServiceImpl.java:1022)
	at org.eclipse.ui.internal.WorkbenchPage.showPart(WorkbenchPage.java:1179)
	at org.eclipse.ui.internal.WorkbenchPage.busyShowView(WorkbenchPage.java:1163)
	at org.eclipse.ui.internal.WorkbenchPage$9.run(WorkbenchPage.java:3828)
	at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:70)
	at org.eclipse.ui.internal.WorkbenchPage.showView(WorkbenchPage.java:3825)
	at org.eclipse.ui.internal.WorkbenchPage.showView(WorkbenchPage.java:3800)
	at org.eclipse.ui.internal.quickaccess.ViewElement.execute(ViewElement.java:71)
	at org.eclipse.ui.internal.quickaccess.SearchField$2.handleElementSelected(SearchField.java:161)
	at org.eclipse.ui.internal.quickaccess.QuickAccessContents.handleSelection(QuickAccessContents.java:350)
	at org.eclipse.ui.internal.quickaccess.QuickAccessContents.access$0(QuickAccessContents.java:340)
	at org.eclipse.ui.internal.quickaccess.QuickAccessContents$6.mouseUp(QuickAccessContents.java:480)
	at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:220)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
	at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4155)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1466)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1489)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1474)
	at org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java:1279)
	at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4001)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3640)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$9.run(PartRenderingEngine.java:1056)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:940)
	at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:99)
	at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:600)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:555)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
	at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:124)
	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:354)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:181)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:601)
	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:636)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:591)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1450)
	at org.eclipse.equinox.launcher.Main.main(Main.java:1426)

To get the exception add the following steps:

5. after restart Ctrl + 3 and open the Outline view
6. grab the view and drag it back into the IDE
==> Exception above is reported
Comment 7 Szymon Ptaszkiewicz CLA 2013-02-12 06:55:19 EST
(In reply to comment #6)
> To get the exception add the following steps:
> 
> 5. after restart Ctrl + 3 and open the Outline view
> 6. grab the view and drag it back into the IDE
> ==> Exception above is reported

Good catch, I can reproduce it. Exception happens even before step 6. The cause is the order in which elements are rendered - we need to render parent before rendering element. Patch will follow.
Comment 8 Szymon Ptaszkiewicz CLA 2013-02-12 08:34:26 EST
Created attachment 226916 [details]
Patch v.0.2

The patch fixes IAE mentioned in comment 6.
Comment 9 Eric Moffatt CLA 2013-02-12 10:41:32 EST
Szymon, the patches are fixing the symptom rather than the real issue which is that when you close the detached window using the red 'x' the resulting model is left in a corrupt state; the 'selectedElement' of the stack is still referencing the Outline view as its selected element (which is illegal since it's not visible).

I think what we should do is to track down *why* the model is correct if I close the Outline view using its 'x' in the tab and wrong when we close the DW using the red 'x'...

It's possible that the fix would be to augment the CleanupAddon to detect that some container no longer has visible children (I believe there's already code to do this there already) and *enforce* that its selectedElement is null ??
Comment 10 Eric Moffatt CLA 2013-02-12 10:54:54 EST
Szymon, I've just taken a closer look and it appears that you're trying to do exactly what I was proposing (sorry about that..;-). I'll take another look but it does look like you're on the correct track.
Comment 11 Szymon Ptaszkiewicz CLA 2013-02-18 05:21:00 EST
(In reply to comment #10)
> Szymon, I've just taken a closer look and it appears that you're trying to
> do exactly what I was proposing (sorry about that..;-). I'll take another
> look but it does look like you're on the correct track.

Thanks, Eric. Let me know if there is anything that needs additional explanation regarding the latest patch.
Comment 12 Szymon Ptaszkiewicz CLA 2013-04-09 08:30:53 EDT
Eric, any update on this one?
Comment 13 Paul Webster CLA 2013-06-03 09:20:37 EDT
*** Bug 392564 has been marked as a duplicate of this bug. ***
Comment 14 Dani Megert CLA 2013-06-05 03:31:05 EDT
This got fixed, see bug 407288.

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