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

Bug 355493

Summary: [Shell] saveFocus causes a widget disposed exception
Product: [RT] RAP Reporter: Adrian Stefanescu <stefanescu.a>
Component: RWTAssignee: Project Inbox <rap-inbox>
Status: RESOLVED FIXED QA Contact:
Severity: major    
Priority: P3    
Version: 1.4   
Target Milestone: 2.1   
Hardware: PC   
OS: Windows 7   
Whiteboard:

Description Adrian Stefanescu CLA 2011-08-23 07:59:37 EDT
Build Identifier: 

This is the method in the Shell class

  final void saveFocus() {
    Control control = display.getFocusControl();
    if( control != null && control != this && this == control.getShell() ) {
      setSavedFocus( control );
    }

Could you add an extra check before control.getShell() to make sure the control is not disposed?


Reproducible: Always

Steps to Reproduce:
1. A modal dialog with a custom is needed. The custom control is something similar to a CCombo control except it has a TableViewer in the list.

2. Close the dialog with ok or cancel.

3. an exception is thrown and the session can't be restored.
Comment 1 Adrian Stefanescu CLA 2011-08-23 08:07:51 EDT
The error is not so easy to reproduce with a simple dialog but here is the stack trace.

!STACK 0
org.eclipse.swt.SWTException: Widget is disposed
	at org.eclipse.swt.SWT.error(SWT.java:3538)
	at org.eclipse.swt.SWT.error(SWT.java:3458)
	at org.eclipse.swt.SWT.error(SWT.java:3429)
	at org.eclipse.swt.widgets.Widget.error(Widget.java:955)
	at org.eclipse.swt.widgets.Widget.checkWidget(Widget.java:891)
	at org.eclipse.swt.widgets.Control.getShell(Control.java:209)
	at org.eclipse.swt.widgets.Shell.saveFocus(Shell.java:1177)
	at org.eclipse.swt.widgets.Display.setActiveShell(Display.java:810)
	at org.eclipse.swt.widgets.Display.removeShell(Display.java:842)
	at org.eclipse.swt.widgets.Shell.releaseParent(Shell.java:1114)
	at org.eclipse.swt.widgets.Widget.dispose(Widget.java:778)
	at org.eclipse.jface.window.Window.close(Window.java:345)
	at org.eclipse.jface.dialogs.Dialog.close(Dialog.java:961)

display.getFocusControl() returns the reference to a Text{Disposed} object when the Window is disposed.

There is a workaround for this: overwrite the dispose methods up to the custom control and move the focus to the parent shell before it's disposed but that's not a solution.

The code that causes this error works on RCP/SWT without problems
Comment 2 Ivan Furnadjiev CLA 2011-08-23 11:33:25 EDT
I think that the problem is in the Display#getFocusControl() that returns the disposed control. In the original SWT code there is a check if the focusControl is disposed:
---
if (focusControl != null && !focusControl.isDisposed ()) {
		return focusControl;
}
return _getFocusControl ();
---
We can return null in case of disposed focusControl as JavaDoc states that null is allowed.
Comment 3 Ivan Furnadjiev CLA 2013-06-12 08:55:42 EDT
I think that this issue should be fixed together with bug 404020. Please reopen the bug if the issue persists in RAP 2.1.