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

Bug 352689

Summary: CDateTime CDT.BUTTON_AUTO throws Widget Is Disposed on close.
Product: z_Archived Reporter: Jermaine Rattray <jermaine.rattray>
Component: NebulaAssignee: Wim Jongman <wim.jongman>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: peter
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Windows 7   
Whiteboard:
Attachments:
Description Flags
mylyn/context/zip
none
mylyn/context/zip none

Description Jermaine Rattray CLA 2011-07-20 22:47:52 EDT
Build Identifier: 20110615-0604

If a CDateTime object is created with the CDT.DROP_DOWN and CDT.BUTTON_AUTO constants an exception is thrown if the widget is focused on exit.
The stacktrace follows. 
org.eclipse.swt.SWTException: Widget is disposed
	at org.eclipse.swt.SWT.error(SWT.java:4283)
	at org.eclipse.swt.SWT.error(SWT.java:4198)
	at org.eclipse.swt.SWT.error(SWT.java:4169)
	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.Text.computeSize(Text.java:462)
	at org.eclipse.nebula.cwt.v.VNative.computeSize(VNative.java:69)
	at org.eclipse.nebula.cwt.v.VControl.computeSize(VControl.java:265)
	at org.eclipse.nebula.cwt.base.BaseCombo$DropComboLayout.layout(BaseCombo.java:77)
	at org.eclipse.nebula.cwt.v.VPanel.layout(VPanel.java:189)
	at org.eclipse.nebula.cwt.v.VPanel.layout(VPanel.java:185)
	at org.eclipse.nebula.cwt.v.VPanel.setBounds(VPanel.java:237)
	at org.eclipse.nebula.cwt.v.VControl.setBounds(VControl.java:732)
	at org.eclipse.nebula.cwt.v.VPanel$2.layout(VPanel.java:68)
	at org.eclipse.swt.widgets.Composite.updateLayout(Composite.java:1263)
	at org.eclipse.swt.widgets.Composite.updateLayout(Composite.java:1249)
	at org.eclipse.swt.widgets.Composite.layout(Composite.java:664)
	at org.eclipse.swt.widgets.Composite.layout(Composite.java:622)
	at org.eclipse.nebula.cwt.base.BaseCombo.setButtonVisible(BaseCombo.java:828)
	at org.eclipse.nebula.cwt.base.BaseCombo$7.handleEvent(BaseCombo.java:788)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1077)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1058)
	at org.eclipse.swt.widgets.Control.sendFocusEvent(Control.java:2822)
	at org.eclipse.swt.widgets.Widget.wmSetFocus(Widget.java:2403)
	at org.eclipse.swt.widgets.Control.WM_SETFOCUS(Control.java:5152)
	at org.eclipse.swt.widgets.Canvas.WM_SETFOCUS(Canvas.java:448)
	at org.eclipse.swt.widgets.Control.windowProc(Control.java:4598)
	at org.eclipse.swt.widgets.Canvas.windowProc(Canvas.java:341)
	at org.eclipse.swt.widgets.Display.windowProc(Display.java:4972)
	at org.eclipse.swt.internal.win32.OS.DestroyWindow(Native Method)
	at org.eclipse.swt.widgets.Control.destroyWidget(Control.java:780)
	at org.eclipse.swt.widgets.Widget.release(Widget.java:818)
	at org.eclipse.swt.widgets.Widget.dispose(Widget.java:446)
	at org.eclipse.nebula.cwt.v.VNative.dispose(VNative.java:77)
	at org.eclipse.nebula.cwt.v.VPanel.dispose(VPanel.java:116)
	at org.eclipse.nebula.cwt.v.VPanel.access$0(VPanel.java:107)
	at org.eclipse.nebula.cwt.v.VPanel$1.handleEvent(VPanel.java:47)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1077)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1058)
	at org.eclipse.swt.widgets.Widget.release(Widget.java:808)
	at org.eclipse.swt.widgets.Composite.releaseChildren(Composite.java:873)
	at org.eclipse.swt.widgets.Widget.release(Widget.java:811)
	at org.eclipse.swt.widgets.Composite.releaseChildren(Composite.java:873)
	at org.eclipse.swt.widgets.Canvas.releaseChildren(Canvas.java:167)
	at org.eclipse.swt.widgets.Decorations.releaseChildren(Decorations.java:773)
	at org.eclipse.swt.widgets.Shell.releaseChildren(Shell.java:1290)
	at org.eclipse.swt.widgets.Widget.release(Widget.java:811)
	at org.eclipse.swt.widgets.Widget.dispose(Widget.java:446)
	at org.eclipse.swt.widgets.Decorations.dispose(Decorations.java:447)
	at org.eclipse.swt.widgets.Shell.dispose(Shell.java:715)
	at org.eclipse.swt.widgets.Decorations.closeWidget(Decorations.java:309)
	at org.eclipse.swt.widgets.Decorations.WM_CLOSE(Decorations.java:1677)
	at org.eclipse.swt.widgets.Control.windowProc(Control.java:4530)
	at org.eclipse.swt.widgets.Canvas.windowProc(Canvas.java:341)
	at org.eclipse.swt.widgets.Decorations.windowProc(Decorations.java:1610)
	at org.eclipse.swt.widgets.Shell.windowProc(Shell.java:2061)
	at org.eclipse.swt.widgets.Display.windowProc(Display.java:4972)
	at org.eclipse.swt.internal.win32.OS.DefWindowProcW(Native Method)
	at org.eclipse.swt.internal.win32.OS.DefWindowProc(OS.java:2525)
	at org.eclipse.swt.widgets.Shell.callWindowProc(Shell.java:498)
	at org.eclipse.swt.widgets.Control.windowProc(Control.java:4623)
	at org.eclipse.swt.widgets.Canvas.windowProc(Canvas.java:341)
	at org.eclipse.swt.widgets.Decorations.windowProc(Decorations.java:1610)
	at org.eclipse.swt.widgets.Shell.windowProc(Shell.java:2061)
	at org.eclipse.swt.widgets.Display.windowProc(Display.java:4972)
	at org.eclipse.swt.internal.win32.OS.DefWindowProcW(Native Method)
	at org.eclipse.swt.internal.win32.OS.DefWindowProc(OS.java:2525)
	at org.eclipse.swt.widgets.Shell.callWindowProc(Shell.java:498)
	at org.eclipse.swt.widgets.Control.windowProc(Control.java:4623)
	at org.eclipse.swt.widgets.Canvas.windowProc(Canvas.java:341)
	at org.eclipse.swt.widgets.Decorations.windowProc(Decorations.java:1610)
	at org.eclipse.swt.widgets.Shell.windowProc(Shell.java:2061)
	at org.eclipse.swt.widgets.Display.windowProc(Display.java:4972)
	at org.eclipse.swt.internal.win32.OS.DispatchMessageW(Native Method)
	at org.eclipse.swt.internal.win32.OS.DispatchMessage(OS.java:2530)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3752)
	at wb1.wbtest1.open(wbtest1.java:100)
	at wb1.wbtest1$1.run(wbtest1.java:57)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
	at wb1.wbtest1.main(wbtest1.java:53)

I did some checking and found the exception is caused by a call the line 'layout(true)' in org.eclipse.nebula.cwt.base.BaseCombo:828. Layout attempts to hide the button, even though it has already been disposed ( the display was already disposed? ).

The solution i found is fairly simple. Others may test it to confirm the issue and solution.
The original code is below
	protected void setButtonVisible(boolean visible) {
		if(BUTTON_ALWAYS == buttonVisibility) {
			visible = true;
		} else if(BUTTON_NEVER == buttonVisibility) {
			visible = false;
		}

		if(checkButton()) {
			button.setVisible(visible);
		}

		layout(true);/* Exception triggered here */
		update();
	}

My attempt at a fix lead me to move the call to layout into the preceding if block.
	protected void setButtonVisible(boolean visible) {
		if(BUTTON_ALWAYS == buttonVisibility) {
			visible = true;
		} else if(BUTTON_NEVER == buttonVisibility) {
			visible = false;
		}

		if(checkButton()) {
			button.setVisible(visible);
			layout(true);/* Moved to here */
		}

		update();
	}

The 'update()' call was not moved as it did not help to cause nor prevent the error.

Reproducible: Always

Steps to Reproduce:
1.Instantiate a CDateTime field using the CDT.BUTTON_AUTO and CDT.DROP_DOWN style bits.
Example: new CDateTime(composite, CDT.DROP_DOWN | CDT.BUTTON_AUTO);

2.Launch the application and set focus to the field, so the button is visible. There is no need to trigger the date selection panel.

3.Close the window and the exception should occur.
Comment 1 Wim Jongman CLA 2011-12-12 09:31:21 EST
Added testcase to prove the bug.
Comment 2 Wim Jongman CLA 2011-12-12 09:31:25 EST
Created attachment 208263 [details]
mylyn/context/zip
Comment 3 Wim Jongman CLA 2011-12-12 10:38:21 EST
I just return when the button is disposed or null.
Comment 4 Wim Jongman CLA 2011-12-12 10:38:24 EST
Created attachment 208264 [details]
mylyn/context/zip
Comment 5 Wim Jongman CLA 2011-12-12 10:38:58 EST
Fixed and released to HEAD. Pick up the build from the nebula download site.