Bug 313711 - API inconsistencies between dispose() and isDisposed()
Summary: API inconsistencies between dispose() and isDisposed()
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 3.6   Edit
Hardware: PC Windows XP
: P3 trivial (vote)
Target Milestone: 3.6 RC3   Edit
Assignee: Lakshmi P Shanmugam CLA
QA Contact:
URL:
Whiteboard:
Keywords: Documentation
Depends on:
Blocks:
 
Reported: 2010-05-20 08:33 EDT by Markus Keller CLA
Modified: 2010-05-25 16:48 EDT (History)
2 users (show)

See Also:


Attachments
patch (10.56 KB, patch)
2010-05-24 07:56 EDT, Lakshmi P Shanmugam CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Markus Keller CLA 2010-05-20 08:33:54 EDT
HEAD


The dispose() and isDisposed() methods of e.g. Widget and Resource have inconsistent APIs.

- isDisposed() says:
 * When a widget/resource has been disposed, it is an error to
 * invoke any other method using the widget/resource.

- dispose() does not state any restrictions and does not declare that it throws an exception (e.g. ERROR_WIDGET_DISPOSED). Furthermore, Widget#dispose() contains this comment:
	/*
	* Note:  It is valid to attempt to dispose a widget
	* more than once.  If this happens, fail silently.
	*/

If the restriction in isDisposed() really applies, then this must be moved up to the class Javadoc and dispose() must declare the exception. You cannot assume that a caller of dispose() reads the Javadocs of all other methods.

However, the more sensible fix is:

- in isDisposed(), replace "any other method" with something like:
"any other method (except {@link #dispose()})"

- in dispose(), you could add a statement telling that the method does nothing when the widget/resource is already disposed

This should be done for all declarations of the the two methods in SWT.
Comment 1 Silenio Quarti CLA 2010-05-20 18:18:14 EDT
A long time ago only isDisposed() was allowed after the widget was disposed. 

We changed this restriction to include dispose() and forgot to update the doc of isDisposed(). dispose() is a noop after the widget is disposed.

Lakshmi please update the doc.
Comment 2 Lakshmi P Shanmugam CLA 2010-05-24 07:56:59 EDT
Created attachment 169666 [details]
patch

updated javadoc for dispose() and isDisposed().
Comment 3 Lakshmi P Shanmugam CLA 2010-05-24 07:59:10 EDT
Fixed in HEAD > 20100524
Comment 4 Lakshmi P Shanmugam CLA 2010-05-24 08:00:07 EDT
.