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

Bug 320672

Summary: [WorkbenchParts] [Compatibility] SWTException when activating an editor with stale content
Product: [Eclipse Project] Platform Reporter: Remy Suen <remy.suen>
Component: UIAssignee: Andrey Loskutov <loskutov>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: daniel_megert, error-reports-inbox, loskutov, M8R-sgiphk, schierlm, vasili.gulevich
Version: 4.1   
Target Milestone: 4.7 M6   
Hardware: All   
OS: All   
See Also: https://git.eclipse.org/r/90666
https://git.eclipse.org/c/platform/eclipse.platform.text.git/commit/?id=919a0022e6f90d59d48982a7e42141187fc5c594
https://git.eclipse.org/r/91372
https://git.eclipse.org/c/platform/eclipse.platform.text.git/commit/?id=f85976cf2deff630448510b18ec517fa21dc9da4
https://git.eclipse.org/r/91429
https://git.eclipse.org/c/platform/eclipse.platform.text.git/commit/?id=42867e454f548f766bc574e480d3e7dda0f675ea
https://git.eclipse.org/r/91437
https://git.eclipse.org/c/platform/eclipse.platform.text.git/commit/?id=5c874dc5531058dfb6d99ed1dda438e1fda3563c
Whiteboard:
Bug Depends on: 511873    
Bug Blocks:    
Attachments:
Description Flags
A Junit test none

Description Remy Suen CLA 2010-07-22 17:19:40 EDT
1. Make a change to a file in your target workspace.
2. Launch your inner.
3. Open the file, you'll get an editor warning you about out-of-date content.
4. Open another file.
5. Activate the first editor.

org.eclipse.swt.SWTException: Widget is disposed
	at org.eclipse.swt.SWT.error(SWT.java:4083)
	at org.eclipse.swt.SWT.error(SWT.java:3998)
	at org.eclipse.swt.SWT.error(SWT.java:3969)
	at org.eclipse.swt.widgets.Widget.error(Widget.java:468)
	at org.eclipse.swt.widgets.Widget.checkWidget(Widget.java:340)
	at org.eclipse.swt.widgets.Control.forceFocus(Control.java:973)
	at org.eclipse.swt.widgets.Control.setFixedFocus(Control.java:2980)
	at org.eclipse.swt.widgets.Composite.setFixedFocus(Composite.java:1039)
	at org.eclipse.swt.widgets.Composite.setFixedFocus(Composite.java:1037)
	at org.eclipse.swt.widgets.Composite.setFixedFocus(Composite.java:1037)
	at org.eclipse.swt.widgets.Composite.setFixedFocus(Composite.java:1037)
	at org.eclipse.swt.widgets.Composite.setFixedFocus(Composite.java:1037)
	at org.eclipse.swt.widgets.Control.fixFocus(Control.java:953)
	at org.eclipse.swt.widgets.Control.setVisible(Control.java:3407)
	at org.eclipse.e4.ui.widgets.CTabFolder.setSelection(CTabFolder.java:2811)
	at org.eclipse.e4.ui.widgets.CTabFolder.setSelection(CTabFolder.java:2819)
	at org.eclipse.e4.ui.widgets.CTabFolder.onMouse(CTabFolder.java:1469)
	at org.eclipse.e4.ui.widgets.CTabFolder$2.handleEvent(CTabFolder.java:264)
Comment 1 Remy Suen CLA 2010-10-18 13:37:12 EDT
The focus event is causing an activation which causes the status controls to be recreated. May possibly be related to bug 325834.

Thread [main] (Suspended (breakpoint at line 806 in Widget))	
	ScrolledComposite(Widget).release(boolean) line: 806	
	ScrolledComposite(Widget).dispose() line: 446	
	CompilationUnitEditor(StatusTextEditor).updatePartControl(IEditorInput) line: 67	
	CompilationUnitEditor(StatusTextEditor).sanityCheckState(IEditorInput) line: 239	
	CompilationUnitEditor(AbstractTextEditor).safelySanityCheckState(IEditorInput) line: 4850	
	AbstractTextEditor$ActivationListener.handleActivation() line: 983	
	AbstractTextEditor$ActivationListener.partActivated(IWorkbenchPart) line: 940	
	PartService.partActivated(IWorkbenchPart) line: 69	
	WorkbenchPage.firePartActivated(MPart) line: 3034	
	WorkbenchPage.access$8(WorkbenchPage, MPart) line: 3023	
	WorkbenchPage$E4PartListener.partActivated(MPart) line: 133	
	PartServiceImpl.firePartActivated(MPart) line: 167	
	PartServiceImpl.setPart(MPart) line: 144	
	NativeMethodAccessorImpl.invoke0(Method, Object, Object[]) line: not available [native method]	
	NativeMethodAccessorImpl.invoke(Object, Object[]) line: 79	
	DelegatingMethodAccessorImpl.invoke(Object, Object[]) line: 43	
	Method.invoke(Object, Object...) line: 618	
	MethodRequestor.execute() line: 52	
	ContextObjectSupplier$ContextInjectionListener.update(IEclipseContext, int, Object[]) line: 75	
	TrackableComputationExt.update(ContextChangeEvent) line: 90	
	EclipseContext.processScheduled(List<Scheduled>) line: 365	
	EclipseContext.set(String, Object) line: 382	
	EclipseContext.activate() line: 637	
	EclipseContext.activateBranch() line: 642	
	PartActivationHistory.activate(MPart, boolean) line: 51	
	PartServiceImpl.activate(MPart, boolean, boolean) line: 471	
	PartServiceImpl.activate(MPart, boolean) line: 453	
	ContributedPartRenderer(AbstractPartRenderer).activate(MPart) line: 105	
	ContributedPartRenderer$2.handleEvent(Event) line: 147	
	EventTable.sendEvent(Event) line: 84	
	Composite(Widget).sendEvent(Event) line: 1053	
	Composite(Widget).sendEvent(int, Event, boolean) line: 1077	
	Composite(Widget).sendEvent(int) line: 1058	
	Shell.setActiveControl(Control) line: 1424	
	Composite(Control).sendFocusEvent(int) line: 2635	
	Composite(Widget).wmSetFocus(int, int, int) line: 2402	
	Composite(Control).WM_SETFOCUS(int, int) line: 4795	
	Composite(Control).windowProc(int, int, int, int) line: 4232	
	Display.windowProc(int, int, int, int) line: 4903	
	OS.SetFocus(int) line: not available [native method]	
	Composite(Control).forceFocus() line: 995	
	Composite(Control).setFixedFocus() line: 2983	
	Composite.setFixedFocus() line: 1039	
	Composite.setFixedFocus() line: 1037	
	ScrolledComposite(Composite).setFixedFocus() line: 1037	
	Composite.setFixedFocus() line: 1037	
	Composite.setFixedFocus() line: 1037	
	Composite.setFixedFocus() line: 1037	
	CTabFolder(Composite).setFixedFocus() line: 1037	
	Composite(Control).fixFocus(Control) line: 953	
	Composite(Control).setVisible(boolean) line: 3410	
	CTabFolder.setSelection(int) line: 2818	
	CTabFolder.setSelection(int, boolean) line: 2826	
	CTabFolder.onMouse(Event) line: 1471	
	CTabFolder$2.handleEvent(Event) line: 266	
	EventTable.sendEvent(Event) line: 84	
	CTabFolder(Widget).sendEvent(Event) line: 1053	
	Display.runDeferredEvents() line: 4083	
	Display.readAndDispatch() line: 3674	
	PartRenderingEngine$6.run() line: 772	
	Realm.runWithDefault(Realm, Runnable) line: 332	
	PartRenderingEngine.run(MApplicationElement, IEclipseContext) line: 681	
	E4Workbench.createAndRunUI(MApplicationElement) line: 104	
	Workbench$3.run() line: 545
Comment 2 John CLA 2011-05-26 09:03:50 EDT
I got this while I had opened files (all were previously saved though, and were not opened in this session, meaning they were still open the last time I started eclipse) and I closed two projects, this caused some(if not all) of the files to remain open but without content (don't remember what was instead of their content, some message saying their project is closed maybe(?) but this exception was on the Error Log (view):
Error setting focus to : org.eclipse.e4.ui.model.application.ui.basic.impl.PartImpl MyFile.java


org.eclipse.swt.SWTException: Widget is disposed
	at org.eclipse.swt.SWT.error(SWT.java:4277)
	at org.eclipse.swt.SWT.error(SWT.java:4192)
	at org.eclipse.swt.SWT.error(SWT.java:4163)
	at org.eclipse.swt.widgets.Widget.error(Widget.java:468)
	at org.eclipse.swt.widgets.Widget.checkWidget(Widget.java:340)
	at org.eclipse.swt.widgets.Control.setFocus(Control.java:3288)
	at org.eclipse.swt.widgets.Composite.setFocus(Composite.java:1038)
	at org.eclipse.swt.widgets.Composite.setFocus(Composite.java:1038)
	at org.eclipse.ui.texteditor.StatusTextEditor.setFocus(StatusTextEditor.java:120)
	at org.eclipse.jdt.internal.ui.javaeditor.JavaEditor.setFocus(JavaEditor.java:2368)
	at org.eclipse.ui.internal.e4.compatibility.CompatibilityPart.delegateSetFocus(CompatibilityPart.java:158)
	at sun.reflect.GeneratedMethodAccessor16.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:56)
	at org.eclipse.e4.core.internal.di.InjectorImpl.invokeUsingClass(InjectorImpl.java:226)
	at org.eclipse.e4.core.internal.di.InjectorImpl.invokeUsingClass(InjectorImpl.java:232)
	at org.eclipse.e4.core.internal.di.InjectorImpl.invoke(InjectorImpl.java:203)
	at org.eclipse.e4.core.contexts.ContextInjectionFactory.invoke(ContextInjectionFactory.java:101)
	at org.eclipse.e4.ui.internal.workbench.PartServiceImpl.activate(PartServiceImpl.java:519)
	at org.eclipse.e4.ui.internal.workbench.PartServiceImpl.activate(PartServiceImpl.java:488)
	at org.eclipse.e4.ui.internal.workbench.swt.AbstractPartRenderer.activate(AbstractPartRenderer.java:105)
	at org.eclipse.e4.ui.workbench.renderers.swt.StackRenderer$ActivationJob.run(StackRenderer.java:133)
	at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35)
	at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:135)
	at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:4138)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3755)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$9.run(PartRenderingEngine.java:944)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:860)
	at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:87)
	at org.eclipse.ui.internal.Workbench$3.run(Workbench.java:542)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:522)
	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(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: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 3 John CLA 2011-05-26 09:39:38 EDT
erm, my bad, Comment 2 was meant for this bug instead:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=344861
Comment 4 Vasili Gulevich CLA 2017-02-08 06:01:53 EST
Created attachment 266724 [details]
A Junit test

Attached is a Junit test to reproduce the issue.

To execute:
Put test in /org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/editor
Expose org.eclipse.ui.tests.internal.ExtendedTextEditor.setDocumentProvider() as a public method.
Comment 5 Andrey Loskutov CLA 2017-02-08 06:04:42 EST
*** Bug 466807 has been marked as a duplicate of this bug. ***
Comment 6 Andrey Loskutov CLA 2017-02-08 06:12:23 EST
(In reply to Vasili Gulevich from comment #4)
> Created attachment 266724 [details]
> A Junit test
> 
> Attached is a Junit test to reproduce the issue.

Thanks!  Amazingly, I was just debugging bug 466807. I think both of them are due bug 511873. I see that setFocus() triggers another setFocus() call, and while the outer setFocus() call is still running, the inner one triggers updatePartControl() which disposes the fStatusControl.
Comment 7 Andrey Loskutov CLA 2017-02-08 12:53:43 EST
Bug 511873 is required but not sufficient to fix this one. I have a patch.
Comment 8 Eclipse Genie CLA 2017-02-08 14:05:09 EST
New Gerrit change created: https://git.eclipse.org/r/90666
Comment 9 Andrey Loskutov CLA 2017-02-08 15:46:13 EST
Steps to reproduce:
1) Disable "refresh on access" in the workspace
2) Open two java editors on two different java files 
3) Close Eclipse 
4) Delete the file for editor which was NOT active 
5) Start Eclipse (editor for the existing file is active) 
6) Click on the tab with deleted file: KABOOM
7) Click previous tab
8) Repeat 6 and 7 to see the error again and again, very nice for debugging.
Comment 10 Andrey Loskutov CLA 2017-02-09 05:04:21 EST
(In reply to Vasili Gulevich from comment #4)
> Created attachment 266724 [details]
> A Junit test

Vasili, I've added your test (slightly modified) to the patch. Any objections?
Comment 12 Eclipse Genie CLA 2017-02-17 09:02:28 EST
New Gerrit change created: https://git.eclipse.org/r/91372
Comment 14 Dani Megert CLA 2017-02-17 09:04:11 EST
(In reply to Eclipse Genie from comment #13)
> Gerrit change https://git.eclipse.org/r/91372 was merged to [master].
> Commit:
> http://git.eclipse.org/c/platform/eclipse.platform.text.git/commit/?id=f85976cf2deff630448510b18ec517fa21dc9da4
> 

This reverted the change because the change introduced illegal dependencies. The workbench layer must not refer to ui.editors or ui.ide.
Comment 15 Eclipse Genie CLA 2017-02-19 02:23:00 EST
New Gerrit change created: https://git.eclipse.org/r/91429
Comment 17 Dani Megert CLA 2017-02-19 12:47:00 EST
(In reply to Eclipse Genie from comment #16)
> Gerrit change https://git.eclipse.org/r/91429 was merged to [master].
> Commit:
> http://git.eclipse.org/c/platform/eclipse.platform.text.git/commit/?id=42867e454f548f766bc574e480d3e7dda0f675ea
> 

Andrey, please add the copyright notice to StatusEditorTest.
Comment 18 Eclipse Genie CLA 2017-02-19 13:43:44 EST
New Gerrit change created: https://git.eclipse.org/r/91437
Comment 19 Andrey Loskutov CLA 2017-02-19 13:55:06 EST
(In reply to Dani Megert from comment #17)
> Andrey, please add the copyright notice to StatusEditorTest.

Done.

(In reply to Eclipse Genie from comment #18)
> New Gerrit change created: https://git.eclipse.org/r/91437

This is the missing header which was eaten by JDT while copying the test code from the old patch via clipboard, see bug 512401.
Comment 21 Andrey Loskutov CLA 2017-02-20 07:43:14 EST
Thanks Vasili for test and review, everything should be merged now.
Comment 22 Andrey Loskutov CLA 2017-03-07 11:01:31 EST
Verified in I20170301-2000 with steps from comment 9.