Community
Participate
Working Groups
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
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.
See also bug 361073, which is the opposite case - top level resource is closed but warning on underlying resource.
Covered by the patch in bug 358903 comment 20. Corresponding tests are: test061a, test061g, test061h.
Resolved by commit 8d45cb26fc5ad244f93e8632d761d46ad4a120cf on behalf of bug 358903.
Verified for 3.8M5 using build I20120122-2000