Community
Participate
Working Groups
+++ This bug was initially created as a clone of Bug #256463 +++ HEAD after bug 256463 COMPILER_PB_DEAD_CODE_IN_TRIVIAL_IF_STATEMENT should also suppress dead code problems *after* the if statement, not only in the else branch: public class X { private static final boolean DEBUG= true; void foo() { if (DEBUG) return; else System.out.println("hello"); // not dead (good) System.out.println("world"); // dead (but should not be) } void bar() { if (DEBUG) { return; } System.out.println("hello"); // dead (but should not be) } }
This feels a corner situation to me.
Thinking more of this, I believe this is actually an evil pattern, which shouldn't exist... so I wouldn't treat it gracefully. if (DEBUG) return;
Reopen to assign
(In reply to comment #2) > Thinking more of this, I believe this is actually an evil pattern, which > shouldn't exist... so I wouldn't treat it gracefully.
Verified for 3.5M4
I disagree with the resolution. The field can have an arbitrary name/meaning and only adding support for the case where we the initial value is 'false' seems wrong to me. Currently this bug is the main reason for the dead code warnings in JDT UI.
Created attachment 204316 [details] proposed fix v1.0 + regression tests This patch makes sure that the merged info from the if and else branches is not unreachable because of a known dead code pattern used as condition, when the COMPILER_PB_DEAD_CODE_IN_TRIVIAL_IF_STATEMENT is disabled. If the else statement is empty or does not otherwise return, the reachable bit of the flow info prior to if-else is taken as the bit for the subsequent info, otherwise the reachability is taken from the else statement
Created attachment 204355 [details] patch for NegativeTest Second part of patch from CVS
Fixed in HEAD with commit 5333a8d6e234b4d5bbcbee365cfa39aafade1032. I don't see the dead code warnings in jdt.ui anymore.
Thanks!
Verified for 3.8 M3 using build id: N20111022-2000