Community
Participate
Working Groups
Example from https://www.eclipse.org/forums/index.php?t=msg&th=1102916&goto=1823096&#msg_1823096 protected void replace(IFile file, String lineSeparator) throws IOException, CoreException { InputStream contents = file.getContents(); String charset = file.getCharset(); BufferedReader reader = new BufferedReader(new InputStreamReader(contents, charset)); CharArrayWriter writer = new CharArrayWriter(); int c; while ((c = reader.read()) != -1) { writer.write(c); } contents.close(); String string = writer.toString(); String newContents = LINE_DELIMITER_PATTERN.matcher(string).replaceAll(lineSeparator); byte[] bytes = newContents.getBytes(charset); file.setContents(new ByteArrayInputStream(bytes), IResource.FORCE, null); } Wrongly complains that 'reader' is never closed.
While the change is triggered by one of the [resource] related fixes in 4.15M1 (not sure which one exactly), the bug appears to be in method FakedTrackingVariable.pickMoreUnsafe(..) which has not been touched in that time frame.
Sorry, I should up updated my other development environments more often. :-( For what it's worth, I have a similar problem in an Oomph method: public static String getContents(IFile file) throws CoreException, IOException { InputStream contents = null; try { contents = file.getContents(); BufferedReader reader = new BufferedReader(new InputStreamReader(contents, file.getCharset())); CharArrayWriter caw = new CharArrayWriter(); int c; while ((c = reader.read()) != -1) { caw.write(c); } return caw.toString(); } finally { IOUtil.closeSilent(contents); } }
New Gerrit change created: https://git.eclipse.org/r/159725
(In reply to Eclipse Genie from comment #3) > New Gerrit change created: https://git.eclipse.org/r/159725 Test & fix. The problem is triggered by code added via bug 519740, the buggy code location, however, is from bug 411098 (Jan 2014).
Gerrit change https://git.eclipse.org/r/159725 was merged to [master]. Commit: http://git.eclipse.org/c/jdt/eclipse.jdt.core.git/commit/?id=07329519f5ac8fd8379eab265d25b2c09a24fd96
(In reply to Eclipse Genie from comment #5) > Gerrit change https://git.eclipse.org/r/159725 was merged to [master]. > Commit: > http://git.eclipse.org/c/jdt/eclipse.jdt.core.git/commit/ > ?id=07329519f5ac8fd8379eab265d25b2c09a24fd96 Released to master for 4.16 M1 Thanks, Ed. (Yes, comment 2 is essentially the same pattern, except that IOUtil.closeSilent() is not among the well-known ways of invoking close() - I don't even know which library provides it).
Verified for Eclipse Version: 2020-06 (4.16) M1 with Build id: I20200406-0600