Bugzilla Bug 4862
  Check for isDisposed() in dispose after sending Dispose Calback (1GLC25X)
Bug List: First Last (This bug is not in your list)   Show list      Query page      Enter new bug
Bug#: 4862   Platform:   Reporter: veronika_irvine@ca.ibm.com (Veronika Irvine)
Product:   OS:   Add CC:
Component:   Version:   CC:
Remove selected CCs
Status: NEW   Priority:  
Resolution:   Severity:  
Assigned To: Silenio_Quarti@ca.ibm.com (Silenio Quarti)   Target Milestone:  

Attachment Type Modified Status Actions
Create a New Attachment (proposed patch, testcase, etc.) View All

Bug 4862 depends on: Show dependency tree
Bug 4862 blocks:
Votes: 0    Show votes for this bug    Vote for this bug

Additional Comments:

Leave as NEW 
Accept bug (change status to ASSIGNED)
Resolve bug, changing resolution to
Resolve bug, mark it as duplicate of bug #
Reassign bug to
Reassign bug to owner of selected component

View Bug Activity   |   Format For Printing

Description: Opened: 2001-10-11 14:24

Run the following example, click on the button and you get the SWT Exception wdiget is disposed.
See Stack trace below.
In the dispose method of a widget, we need to check that the widget has not been disposed in the Dispose callback.

public static void main(String args[]){
	Display display = new Display ();
	Shell shell = new Shell();
	shell.setLayout(new org.eclipse.swt.layout.GridLayout());
	shell.setBounds(100,30, 800,600);
	final Composite panel = new Composite(shell, SWT.BORDER);
	final Button button = new Button(panel, 0);
	button.setText("dispose button");
	final SelectionAdapter[] selectionListener = new SelectionAdapter[1];
	selectionListener[0] = new SelectionAdapter(){
		public void widgetSelected (org.eclipse.swt.events.SelectionEvent e){
	final DisposeListener[] disposeListener = new DisposeListener[1];
	disposeListener[0] = new DisposeListener(){
		public void widgetDisposed(org.eclipse.swt.events.DisposeEvent e){
	while (!shell.isDisposed ()) {
		if (!display.readAndDispatch ()) display.sleep ();

org.eclipse.swt.SWTException: Widget is disposed
	at org.eclipse.swt.SWT.error(SWT.java:1818)
	at org.eclipse.swt.SWT.error(SWT.java:1750)
	at org.eclipse.swt.widgets.Widget.error(Widget.java:379)
	at org.eclipse.swt.widgets.Control.getDisplay(Control.java:597)
	at org.eclipse.swt.widgets.Control.unsubclass(Control.java:2365)
	at org.eclipse.swt.widgets.Control.releaseWidget(Control.java:1247)
	at org.eclipse.swt.widgets.Button.releaseWidget(Button.java:344)
	at org.eclipse.swt.widgets.Widget.dispose(Widget.java:366)
	at veronika._Scrapbook$1.widgetSelected(_Scrapbook.java:43)
	at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:85)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:54)
	at org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java:645)
	at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:1359)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:1160)
	at veronika._Scrapbook.main(_Scrapbook.java:58)
Exception in thread "main" 


------- Additional Comment #1 From DJ Houghton 2001-10-29 16:44 -------
2.0 007

------- Additional Comment #2 From Veronika Irvine 2004-09-24 10:09 -------
In 3.1, I get a different error now on Windows:

	at org.eclipse.swt.widgets.Control.deregister(Control.java:498)
	at org.eclipse.swt.widgets.Control.releaseWidget(Control.java:1496)
	at org.eclipse.swt.widgets.Button.releaseWidget(Button.java:364)
	at org.eclipse.swt.widgets.Widget.dispose(Widget.java:368)
	at veronika.Newsgroup$1.widgetSelected(Newsgroup.java:25)
	at org.eclipse.swt.widgets.TypedListener.handleEvent
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:82)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:796)
	at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:2783)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2442)
	at veronika.Newsgroup.main(Newsgroup.java:40)

Bug List: First Last (This bug is not in your list)   Show list      Query page      Enter new bug
This is Bugzilla: the Mozilla bug system. For more information about what Bugzilla is and what it can do, see bugzilla.org.
Actions: New | Query | bug # | Reports   New Account | Log In