Bug 8414

Summary: Incorrect "unused variable" warning?
Product: [Eclipse Project] JDT Reporter: Jared Burns <jared_burns>
Component: CoreAssignee: Philipe Mulet <philippe_mulet>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P1    
Version: 2.0   
Target Milestone: 2.0 M3   
Hardware: Other   
OS: other   
Whiteboard:

Description Jared Burns CLA 2002-01-24 15:00:39 EST
The following code results in a warning that "the local variable i is never
used." Since DEBUG is a final variable set to false, the variable i will never
be hit, however, this is only part of the truth which is that none of the code
inside the if statement will be run.

If we're going to be this smart about detecting when code won't be run, we need
to give the whole truth. I suggest that in this case we should either give no
warning or give a warning that the code in the if statement is unreachable.

public class Foo {
  private static final boolean DEBUG= false;

  public void foo() {
    if (DEBUG) {
      for (int i= 0; i < 10; i++) { // Warning appears here
        System.out.println(new Integer(i));
      }
    }
  }
}
Comment 1 Philipe Mulet CLA 2002-01-24 18:09:54 EST
Thought these intempestive warnings were already disabled.
Need to investigate
Comment 2 Philipe Mulet CLA 2002-01-28 13:12:04 EST
Was testing the IsReachableMASK bit, which is always set to true by default, 
and cleared on non reachable statements. Nested nodes aren't set correctly, and 
are supposed to be tested (code gen will not investigate unreachable statement 
subnodes). 
Fixed by using a distinct bit for LocalDeclaration reachability.