Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 294593 - [Resources] Accessors should fail in case of disposed resource
Summary: [Resources] Accessors should fail in case of disposed resource
Status: RESOLVED FIXED
Alias: None
Product: RAP
Classification: RT
Component: RWT (show other bugs)
Version: 1.3   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 1.3 M4   Edit
Assignee: Dominik Ebert CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-11-09 08:10 EST by Benjamin Muskalla CLA
Modified: 2009-12-03 10:07 EST (History)
2 users (show)

See Also:


Attachments
First draft (40.48 KB, patch)
2009-11-24 07:20 EST, Dominik Ebert CLA
ruediger.herrmann: iplog+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Benjamin Muskalla CLA 2009-11-09 08:10:17 EST
In case we have API that takes a resource, we should check if the resource is disposed and throw the corresponding exception as stated in the javadoc. Currently we don't care about this case.

Here is a (I hope full list) of APIs we need to care about:
CTabFolder#setSelectionBackground
CTabItem#setFont
Control#setBackground
Control#setBackgroundImage
Control#setCursor
Control#setFont
Control#setForeground
TableItem#setBackground
TableItem#setBackground(int,Color)
TableItem#setFont
TableItem#setFont(int,Font)
TableItem#setForeground
TableItem#setForeground(int,Color)
TreeItem#setBackground
TreeItem#setBackground(int,Color)
TreeItem#setFont
TreeItem#setFont(int,Font)
TreeItem#setForeground
TreeItem#setForeground(int,Color)
Comment 1 Dominik Ebert CLA 2009-11-23 10:42:32 EST
A question about the Control#setBackgroundImage(Image image) method:

The method needs an Image object. The images that i get via 
Graphics.getImage() are not disposable because they are created with a factory. Is it possible to append a small Image file to the Unit Test for this method to create a disposed image? 
Or is there another way to create an Image object and dispose it afterwards?
The Constructor Image(Device, Image, boolean) won't work with an Image got via Graphics.getImage() as an argument.
Comment 2 Rüdiger Herrmann CLA 2009-11-24 02:53:22 EST
Have a look at Image_Test#testDispose(). In this test case, a disposable image is created.
Comment 3 Dominik Ebert CLA 2009-11-24 07:20:02 EST
Created attachment 152938 [details]
First draft

I implemented that the methods above throw an IllegalArgumentException (SWT.ERROR_INVALID_ARGUMTENT) if the argument is disposed.

I also added this behaviour in the following methods:

TreeItem#setImage(...)
TableItem#setImage(...)
Item#setImage(...)

As i got the hint to look for a disposable Image, i added InputStream.close() to the method Image#testDispose() and all further test methods that require an InputStream object to create an Image.

The IllegalArgumentException is missing in all classes that override Item#setImage(Image), so i left a comment in CTabItem#setImage(...) which doesnt't have any Javadoc comment.
Comment 4 Rüdiger Herrmann CLA 2009-12-03 10:04:36 EST
(In reply to comment #3)
> [ ... ]
> The IllegalArgumentException is missing in all classes that override
> Item#setImage(Image), so i left a comment in CTabItem#setImage(...) which
> doesnt't have any Javadoc comment.
I don't see a problem there, since all mentioned methods call super.setImage()
Comment 5 Rüdiger Herrmann CLA 2009-12-03 10:07:59 EST
Applied patch to CVS HEAD