Bug 360908 - Avoid resource leak warning when the underlying/chained resource is closed explicitly
Summary: Avoid resource leak warning when the underlying/chained resource is closed ex...
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.8   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.8 M5   Edit
Assignee: Stephan Herrmann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on: 358903
Blocks:
  Show dependency tree
 
Reported: 2011-10-14 01:09 EDT by Deepak Azad CLA
Modified: 2012-01-24 09:53 EST (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Deepak Azad CLA 2011-10-14 01:09:26 EDT
In the following snippet there is a 'Resource leak: 'reader' is never closed' warning. However, the underlying resource is closed explicitly so practically it is not an issue. Can we avoid these kinds of warnings? Do we want to - I mean is it a bad practice to close the underlying resource instead of the top level one?

--------------------------------------------------------------------
boolean load1(final URL url) throws IOException {
	InputStreamReader inputStreamReader = new InputStreamReader(url.openStream());
	try {
		final BufferedReader reader = new BufferedReader(inputStreamReader);                    //warning
		int ch;
		while ((ch = reader.read()) != -1) {
			System.out.println(ch);
		}
	} finally {
		try {
			if (inputStreamReader != null)
				inputStreamReader.close();
		} catch (IOException x) {
		}
	}
	return false;
}
--------------------------------------------------------------------

This is a simplified case of the following warning in o.e.jdt.ui -
Resource leak: 'reader' is never closed	AbstractSpellDictionary.java	/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/spelling/engine	line 626
Comment 1 Markus Keller CLA 2011-10-14 09:47:48 EDT
The compiler should also use the whitelist for wrapper resources here (Group 1 from bug 358903 comment 9). I.e. warn only if the wrapper is not in the whitelist.
Comment 2 Deepak Azad CLA 2011-10-15 23:36:09 EDT
See also bug 361073, which is the opposite case - top level resource is closed but warning on underlying resource.
Comment 3 Stephan Herrmann CLA 2012-01-07 20:21:42 EST
Covered by the patch in bug 358903 comment 20.
Corresponding tests are: test061a, test061g, test061h.
Comment 4 Stephan Herrmann CLA 2012-01-15 09:30:07 EST
 
Resolved by commit 8d45cb26fc5ad244f93e8632d761d46ad4a120cf
on behalf of bug 358903.
Comment 5 Ayushman Jain CLA 2012-01-24 09:53:36 EST
Verified for 3.8M5 using build I20120122-2000