Community
Participate
Working Groups
I'm not sure if this use case is already included in the 3.0 enhancements but it is not recognized in 2.1.2. Thus, I'm adding it to bugzilla. public void myMethod() { boolean performOK = false; [some opertations that never modify performOk (no write access to performOk)] if(performOK && .....) { // this code will be unreachable // jdt compile can recognize this but doesn't in 2.1.2 } }
As per JLS, this code cannot be flagged as unreachable. But an extra warning for such a scenario could be useful indeed. Though it requires quite a bit of work in order to get there. Will consider later.
*** Bug 51952 has been marked as a duplicate of this bug. ***
*** Bug 110544 has been marked as a duplicate of this bug. ***
reopening
Re: comment 1 It will now work if the variable is made a constant. public void myMethod(){ final boolean performOK = false;
Created attachment 118447 [details] Proposed patch (hacking at Stuttgart airport on way back from ESE)
Added FlowAnalysisTest#test052-057
Created attachment 118458 [details] Better patch
Created attachment 118586 [details] Final patch Enabled the warning in test suites
Released for 3.5M4. Fixed
Created attachment 118651 [details] Addition to previous patch Takes care of scenario like: int i = false && b ? 0 : 1; which is now reporting 2 instances of dead code (instead of one before extra patch). ---------- 1. WARNING in X.java (at line 3) int i = false && b ? 0 : 1; ^ Dead code ---------- 2. WARNING in X.java (at line 3) int i = false && b ? 0 : 1; ^ Dead code ----------
Also added FlowAnalysisTest#test058-059, and enabled the diagnostic on entire compiler test suites.
Verified for 3.5M4 using I20081209-0100
Is it by intention that this diagnostic is configurable via preferences/command line arg, but not suppressable using a @SuppressWarnings("deadCode") annotation? This looks inconsistent to me. Also the discussion in bug 256463 doesn't mention suppressing using an annotation. Just an oversight?