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:  
URL:
Summary:
Keywords:

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);
	shell.open();
 
	final Composite panel = new Composite(shell, SWT.BORDER);
	panel.setBounds(20,430,100,100);
 
	final Button button = new Button(panel, 0);
	button.setText("dispose button");
	button.setBounds(7,7,80,70);
	final SelectionAdapter[] selectionListener = new SelectionAdapter[1];
	selectionListener[0] = new SelectionAdapter(){
		public void widgetSelected (org.eclipse.swt.events.SelectionEvent e){
			button.dispose();
		}
	};
	button.addSelectionListener(selectionListener[0]);
 
	final DisposeListener[] disposeListener = new DisposeListener[1];
	disposeListener[0] = new DisposeListener(){
		public void widgetDisposed(org.eclipse.swt.events.DisposeEvent e){
			button.removeDisposeListener(disposeListener[0]);
			panel.dispose();
		}
	};
	button.addDisposeListener(disposeListener[0]);
 
	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" 

NOTES:

------- Additional Comment #1 From DJ Houghton 2001-10-29 16:44 -------
PRODUCT VERSION:
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:

java.lang.NullPointerException
	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
(TypedListener.java:89)
	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