Community
Participate
Working Groups
Test case: import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.io.Reader; public class Test { public static void main(String[] args) throws FileNotFoundException { Reader a = (Reader)new BufferedReader(new FileReader("a")); try { a.close(); } catch (IOException e) { e.printStackTrace(); } } } I get a warning at new BufferedReader(a) that says, "Resource leak: '<unassigned Closeable value>' is never closed". I think it is a false warning. Please check.
I can reproduce and there's an easy workaround, too: Omit the unnecessary cast to Reader (why would you ever cast an allocation expression? It already has the most precise type possible, and up-casts are never needed anyway). For some reason the cast obscures the fact that the BufferedReader is assigned to 'a'. I'll take a look, time permitting.
Also note the warning issued at compliance 1.7: 1. WARNING in /tmp/Test.java (at line 9) Reader a = (Reader)new BufferedReader(new FileReader("a")); ^ Resource 'a' should be managed by try-with-resource :)
Stephan, Thanks for looking at this problem. I know there is workaround, but our java code is generated and we need to add the additional cast. The case is just a simplified sample to demonstrate the problem.
This one *might* be simple enough to sneak in late into 4.4
Putting this issue on standby.
New Gerrit change created: https://git.eclipse.org/r/45163
The immediate problem was easy to fix indeed: just peel-off the cast when inspecting the right hand side in the assignment. Unfortunately this revealed some hidden bugs in the implementation (regressions in ResourceLeakTests). Here's what the patch under test will change in addition to the immediate fix: More initialization of the bits in UFI that were introduced for bug 453483: If a flow info is growing (more than 64 locals), the newly allocated extra storage was lacking initialization for these new bits. Fixed by: - Inventing a new tag bit UNROOTED, to mark those flowInfos that need to set the IN/INN bits to -1L. - Extracting and enhancing createExtraSpace(length) FVT.reportRecordedErrors() under some circumstances reported problems even if the nullStatus was UNKNOWN. Fixed by: - Consulting the null status, AND, - Checking if perhaps all recorded locations agree on status NULL, for the case the flowInfo was unreachable (and therefore had no null info). FTV.mergeCloseStatus() was merging NULL and UNKNOWN into POTENTIALLY_NULL, which is wrong when UNKNOWN really expresses: no null information. Fixed by one additional check.
Gerrit change https://git.eclipse.org/r/45163 was merged to [master]. Commit: http://git.eclipse.org/c/jdt/eclipse.jdt.core.git/commit/?id=58c4c99d95f495c1408134b2cc53ce1127ec5a07
.
Verified for Eclipse 4.5 Mars M7 Build id: I20150422-1000