Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 347573 - Graphics_Test lets Fixture#tearDown() fail by leaving open an inputStreams
Summary: Graphics_Test lets Fixture#tearDown() fail by leaving open an inputStreams
Status: RESOLVED FIXED
Alias: None
Product: RAP
Classification: RT
Component: RWT (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows All
: P3 normal (vote)
Target Milestone: 1.5 M1   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 347446
  Show dependency tree
 
Reported: 2011-05-29 06:48 EDT by Rüdiger Herrmann CLA
Modified: 2011-06-03 05:52 EDT (History)
1 user (show)

See Also:


Attachments
Proposed fix for Graphics_Test#testGetImageWithClassLoader (1.66 KB, patch)
2011-06-03 05:40 EDT, Rüdiger Herrmann CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Rüdiger Herrmann CLA 2011-05-29 06:48:17 EDT
When running tests outside the RWTAllTestSuite, Fixture#tearDown fails with an IllegalStateException while cleaning up the web context directory. The reason is that files could not be deleted.
For example running the Graphics_Test raises the following exception in #testGetImageWithClassLoader
java.lang.IllegalStateException: Could not delete: C:\Users\Ruediger\AppData\Local\Temp\testapp\test.gif
	at org.eclipse.rwt.Fixture.doDelete(Fixture.java:437)
	at org.eclipse.rwt.Fixture.delete(Fixture.java:410)
	at org.eclipse.rwt.Fixture.doDelete(Fixture.java:431)
	at org.eclipse.rwt.Fixture.delete(Fixture.java:410)
	at org.eclipse.rwt.Fixture.deleteWebContextDirectories(Fixture.java:171)
	at org.eclipse.rwt.Fixture.disposeOfApplicationContext(Fixture.java:113)
	at org.eclipse.rwt.graphics.Graphics_Test.tearDown(Graphics_Test.java:253)
	...

Trying to delete the file manually while pausing the test just before tearDown() is called, reveals the reason why the file cannot be deleted: "The action cannot be completed because the file is open in Java Platform SE binary". 
This can probably only be observed on Windows, as to my knowledge other operation systems don't prevent files from being deleted while still in use. Nevetheless it indicates a resource leak.

Running the RWTAllTestSuite works because it sets the Fixture#usePerformanceOptimizations to true before running the tests, which in turn prevents the web context directory from being cleaned up.
Comment 1 Rüdiger Herrmann CLA 2011-05-29 12:31:19 EDT
After further investigation it turned out that two tests in Graphics_Test cause the problem as they (or the code under test) leave open an input stream:
* testGetImageWithClassLoader
* testGetImageWithInputStream
Changed the bug summary accordingly
Comment 2 Rüdiger Herrmann CLA 2011-06-03 04:57:15 EDT
Fixed testGetImageWithInputStream by closing the input stream. Changes are in CVS HEAD.
Comment 3 Rüdiger Herrmann CLA 2011-06-03 05:40:10 EDT
Created attachment 197296 [details]
Proposed fix for Graphics_Test#testGetImageWithClassLoader

Tis patch fixes the issue by closing the class resource input stream in ImageFactory#createImage(String,ClassLoader)
Comment 4 Rüdiger Herrmann CLA 2011-06-03 05:51:00 EDT
Applied patch from atachment 197296 to CVS HEAD.
If you don't like to try-catch block, pleasse see bug  348190.
@Ralf: Do you have a chance to revise this fix? Is this a candidate for 1.4.1?
Comment 5 Rüdiger Herrmann CLA 2011-06-03 05:52:52 EDT
Marking as FIXED (see comment #4)