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

Bug 295046

Summary: [EditorMgmt] Widget is disposed error when going back to compare editor
Product: [Eclipse Project] Platform Reporter: Dani Megert <daniel_megert>
Component: UIAssignee: Platform UI Triaged <platform-ui-triaged>
Status: CLOSED DUPLICATE QA Contact: Remy Suen <remy.suen>
Severity: major    
Priority: P3 CC: pwebster, tomasz.zarna
Version: 3.6   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description Dani Megert CLA 2009-11-13 03:55:05 EST
I20091110-0800.

1. start new workspace
2. create simple project p
3. create file f
4. edit and save several times to create local history entries
5. compare current with previous from local history
6. compare the two oldest with each other
7. bring text editor for f to front
8. click 'Back'

==>

!ENTRY org.eclipse.ui.workbench 4 2 2009-11-13 09:50:23.737
!MESSAGE Problems occurred when invoking code from plug-in: "org.eclipse.ui.workbench".
!STACK 0
org.eclipse.swt.SWTException: Widget is disposed
	at org.eclipse.swt.SWT.error(SWT.java:4031)
	at org.eclipse.swt.SWT.error(SWT.java:3946)
	at org.eclipse.swt.SWT.error(SWT.java:3917)
	at org.eclipse.swt.widgets.Widget.error(Widget.java:463)
	at org.eclipse.swt.widgets.Widget.checkWidget(Widget.java:336)
	at org.eclipse.swt.widgets.Composite.setFocus(Composite.java:995)
	at org.eclipse.compare.CompareViewerSwitchingPane.setFocus(CompareViewerSwitchingPane.java:363)
	at org.eclipse.compare.CompareEditorInput.setFocus2(CompareEditorInput.java:882)
	at org.eclipse.compare.internal.CompareEditor.setFocus(CompareEditor.java:504)
	at org.eclipse.ui.internal.PartPane.setFocus(PartPane.java:332)
	at org.eclipse.ui.internal.EditorPane.setFocus(EditorPane.java:127)
	at org.eclipse.ui.internal.WorkbenchPage$3.run(WorkbenchPage.java:625)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
	at org.eclipse.core.runtime.Platform.run(Platform.java:888)
	at org.eclipse.ui.internal.WorkbenchPage.activatePart(WorkbenchPage.java:620)
	at org.eclipse.ui.internal.WorkbenchPage.setActivePart(WorkbenchPage.java:3527)
	at org.eclipse.ui.internal.WorkbenchPage.activate(WorkbenchPage.java:613)
	at org.eclipse.ui.internal.WorkbenchPage.busyOpenEditorBatched(WorkbenchPage.java:2869)
	at org.eclipse.ui.internal.WorkbenchPage.busyOpenEditor(WorkbenchPage.java:2762)
	at org.eclipse.ui.internal.WorkbenchPage.access$11(WorkbenchPage.java:2754)
	at org.eclipse.ui.internal.WorkbenchPage$10.run(WorkbenchPage.java:2705)
	at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:70)
	at org.eclipse.ui.internal.WorkbenchPage.openEditor(WorkbenchPage.java:2701)
	at org.eclipse.ui.internal.WorkbenchPage.openEditor(WorkbenchPage.java:2685)
	at org.eclipse.ui.internal.WorkbenchPage.openEditor(WorkbenchPage.java:2676)
	at org.eclipse.ui.internal.NavigationHistoryEntry.restoreLocation(NavigationHistoryEntry.java:66)
	at org.eclipse.ui.internal.NavigationHistory.gotoEntry(NavigationHistory.java:455)
	at org.eclipse.ui.internal.NavigationHistory.shiftEntry(NavigationHistory.java:520)
	at org.eclipse.ui.internal.NavigationHistory.backward(NavigationHistory.java:504)
	at org.eclipse.ui.internal.NavigationHistoryAction.run(NavigationHistoryAction.java:242)
	at org.eclipse.jface.action.Action.runWithEvent(Action.java:498)
	at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:584)
	at org.eclipse.jface.action.ActionContributionItem.access$2(ActionContributionItem.java:501)
	at org.eclipse.jface.action.ActionContributionItem$6.handleEvent(ActionContributionItem.java:452)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1002)
	at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3917)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3510)
	at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2404)
	at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2368)
	at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2220)
	at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:500)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:493)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
	at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:113)
	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:194)
	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:367)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
	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:611)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:566)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1363)
	at org.eclipse.equinox.launcher.Main.main(Main.java:1339)
	at org.eclipse.core.launcher.Main.main(Main.java:34)
Comment 1 Dani Megert CLA 2009-11-13 03:55:55 EST
Bug 146021 reports a similar issue with a less frequent scenario.
Comment 2 Tomasz Zarna CLA 2009-11-18 07:35:51 EST
It does not happen each time, does it? I've tried the steps you provided with no luck. So I started doing variations of the steps (including opening New Editor for the Compare editor) and I got the exception only once. Unfortunately I don't remember the sequence since I was clicking around like crazy. This also mean that I'm not sure if what I saw was this bug or bug 146021 (steps provided there work each time and it looks bad :/ I will give it another shot soon.

btw, I tried it on I20091110-0800 and I20091117-1545.
Comment 3 Dani Megert CLA 2009-11-18 08:07:34 EST
I can consistently reproduce using I20091117-1545 on WindowsXP and the steps from comment 0.
Comment 4 Tomasz Zarna CLA 2009-11-18 08:36:32 EST
Got it, missed 5. from comment 0. My mistake.
Comment 5 Tomasz Zarna CLA 2009-11-18 11:40:38 EST
The problem here is that we reuse the Compare Editor open for "current vs previous from local" and set the new input for comparison of "the two oldest". Then when "Back" is clicked Eclipse tries to restore the first editor. This is what should happen:
a) remove a navigation history entry for the first comparison ("current vs previous"). This is the culprit actual causing the exception (ie Eclipse tries to restore the first editor which is gone, reused).
b) update navigation history with the new Compare Editor ("the two oldest"). New editor input (we reuse editor part by setting new input) should mean new navigation history entry. We cannot merge[1] nav entry for the old compare editor with the new one because inputs are not equal. What we could do is to update the history in reaction to partInputChanged[2] event. However, the problem is that the old compare editor we would like to close cannot be found (using IEditorInput.equals[3]) since the input has been already replaced[4] ie in CompareEditor.setInput[5] the new input is set first and the IWorkbenchPartConstants.PROP_INPUT property change is fired later.
c) add a nav entry for the new ("the two oldest") compare editor. To achieve this when reusing Compare editor we will need to call IWorkbenchPage.reuseEditor(IReusableEditor, IEditorInput) rather than calling simply IReusableEditor.setInput(IEditorInput) as it happens right now in CompareUIPlugin.internalOpenEditor(CompareEditorInput, IWorkbenchPage, IReusableEditor, boolean). The reason for this is that CompareEditor (implementation of IReusableEditor) doesn't call navigationHistory.markEditor(IReusableEditor) when IWorkbenchPage.reuseEditor does.

I'm on it.

[1] org.eclipse.ui.internal.NavigationHistoryEntry.mergeInto(NavigationHistoryEntry)
[2] org.eclipse.ui.internal.NavigationHistory.NavigationHistory(...).new IPartListener2(){...}.partInputChanged(IWorkbenchPartReference)
[3] org.eclipse.ui.internal.NavigationHistory rev 1.47, line
[4] org.eclipse.compare.internal.CompareUIPlugin.internalOpenEditor(CompareEditorInput, IWorkbenchPage, IReusableEditor, boolean) when input!=null
[5] org.eclipse.compare.internal.CompareEditor.doSetInput(IEditorInput)
Comment 6 Tomasz Zarna CLA 2009-11-19 06:10:24 EST
After further investigation I found bug 162939 in Platform/UI which looks very similar to this report. The UI bug is about reopening (navigating back) a closed, reused compare editor. On this report we're dealing with a situation when we navigate back to an reused but still open compare editor. The problem here is that navigation history does't know that the editor input has changed ie the history is not updated properly and it's trying to navigate to the editor with the old input. So like bug 162939 I think this is a workbench issue, but let me know if I can be of any assistance. Moving to UI for comment.
Comment 7 Tomasz Zarna CLA 2009-11-19 06:53:48 EST
I wonder if this is a more general issue with navigating between IReusableEditors with switched inputs. If someone from UI give me a tip where to start I will try to provide a test to verify it.
Comment 8 Remy Suen CLA 2009-12-07 13:13:38 EST
(In reply to comment #7)
> I wonder if this is a more general issue with navigating between
> IReusableEditors with switched inputs. If someone from UI give me a tip where
> to start I will try to provide a test to verify it.

I tried doing the same thing via 'File > Save As...' and a regular text editor, changing its file input to the new file, but no success in reproducing an error so far.
Comment 9 Tomasz Zarna CLA 2009-12-08 06:24:35 EST
Is there a way to simulate switching inputs programmatically? If yes I could try to provide a unit test for that scenario.
Comment 10 Remy Suen CLA 2009-12-09 10:31:12 EST
(In reply to comment #9)
> Is there a way to simulate switching inputs programmatically?

I believe that would be a matter of calling IWorkbenchPage's reuseEditor(IReusableEditor, IEditorInput) method.

Bug 79991 may be another related bug.
Comment 11 Dani Megert CLA 2009-12-16 06:59:11 EST

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