Community
Participate
Working Groups
Build Identifier: I20111027-1800 The println statement below is incorrectly marked as dead code, presumably because the static analysis of whether 'data' is null does not consider that the IOException could come from stream.close() after stream.read() completes successfully. public static void main(String[] args) { String data = null; try (FakeStream stream = new FakeStream()) { data = stream.read(); } catch (IOException e) { if (data != null) System.out.println("got " + data); // marked incorrectly as dead code } } Reproducible: Always Steps to Reproduce: Compile and run the attached test case. The println statement will be marked with a dead code warning, but running the program shows that the println is executed.
Created attachment 208211 [details] Test case to demonstrate issue
Ayush, please take a look, if fix is clean & safe, we will consider backport to 3.7.2.
(In reply to comment #0) > Compile and run the attached test case. The println statement will be marked > with a dead code warning, but running the program shows that the println is > executed. At least the println is not "optimized" out, which I believe is a merit of bug 338234.
Created attachment 264292 [details] Another complete test case, showing difference between try-with-resources and expanded try form This code demonstrates the issue as of Neon, and shows the difference between the try-with-resources form and the expanded form. Eclipse Java EE IDE for Web Developers. Version: Neon Release (4.6.0) Build id: 20160613-1800
I'm able to reproduce this as of 2016-09-20 in Eclipse Neon, 4.6.0. I've added another attachment that demonstrates the issue more fully, and contrasts the try-with-resources form with the expanded try form. I ran into this and also asked a Stack Overflow question about it (http://stackoverflow.com/q/39598715/1281433). Eclipse Java EE IDE for Web Developers. Version: Neon Release (4.6.0) Build id: 20160613-1800
See also https://stackoverflow.com/q/50351907/6505250
bulk move out of 4.8
Bulk move out of 4.9
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant. -- The automated Eclipse Genie.