Bug 8414 - Incorrect "unused variable" warning?
Summary: Incorrect "unused variable" warning?
Status: RESOLVED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 2.0   Edit
Hardware: Other other
: P1 normal (vote)
Target Milestone: 2.0 M3   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-01-24 15:00 EST by Jared Burns CLA
Modified: 2002-01-28 13:12 EST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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.