Bug 166641 - [compiler] uninitialized variable not reported in if (false) block
Summary: [compiler] uninitialized variable not reported in if (false) block
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.2.1   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.2.2   Edit
Assignee: Maxime Daniel CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-12-04 10:30 EST by Christopher Sahnwaldt CLA
Modified: 2007-01-16 05:00 EST (History)
2 users (show)

See Also:


Attachments
Suggested fix + test cases (4.71 KB, patch)
2006-12-05 04:40 EST, Maxime Daniel CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Christopher Sahnwaldt CLA 2006-12-04 10:30:31 EST
Build ID: M20060921-0945

Steps To Reproduce:
Compile and run the following program with Eclipse:

public class Playground
{
  public static void main(String[] args)
  {
    if (false)
    {
      String string;
      System.out.println(string);
    }
  }
}

It compiles, runs, and does nothing.

Try to compile the program with javac - fails with the message:

Playground.java:8: variable string might not have been initialized
    System.out.println(string);
                       ^
1 error

More information:
I just ran an Eclipse update. Here's an excerpt from my Configuration Details:

org.eclipse.jdt.apt.core_3.2.1.R32x_v20060822-2100.jar
org.eclipse.jdt.apt.ui_3.2.1.R32x_v20060822-2100.jar
org.eclipse.jdt.core.manipulation_1.0.1.r321_v20060721.jar
org.eclipse.jdt.core_3.2.2.jar
org.eclipse.jdt.debug.ui_3.2.1.r321_v20060918.jar
org.eclipse.jdt.debug_3.2.1.r321_v20060731/
org.eclipse.jdt.doc.isv_3.2.1.r321_v20060907.jar
org.eclipse.jdt.doc.user_3.2.0.v20060605-1400.jar
org.eclipse.jdt.junit.runtime_3.2.1.r321_v20060721/
org.eclipse.jdt.junit4.runtime_1.0.1.r321_v20060905.jar
org.eclipse.jdt.junit_3.2.1.r321_v20060810/
org.eclipse.jdt.launching_3.2.1.r321_v20060731.jar
org.eclipse.jdt.source_3.2.1.r321_v20060905-R4CM1Znkvre9wC-/
org.eclipse.jdt.ui_3.2.1.r321_v20060907.jar
org.eclipse.jdt_3.2.1.r321_v20060823.jar
Comment 1 Philipe Mulet CLA 2006-12-04 11:25:45 EST
Maxime - pls show me the patch once available. Feels to me like a regression. 
Comment 2 Philipe Mulet CLA 2006-12-05 03:46:29 EST
NOTE: this code must not yield an error. We should thus distinguish based on the scope of the variable (defined within/outside fake reachable code).

public class X {
	public static void main(String[] args) {
		String string;
		if (false) {
			System.out.println(string);
		}
	}
}
Comment 3 Philipe Mulet CLA 2006-12-05 03:47:52 EST
Need to also check subscopes scenarii (where more than one level of scope is defined within fake reachable land).
Comment 4 Maxime Daniel CLA 2006-12-05 04:18:32 EST
Released FlowAnalysisTest#37 (inactive) and 38. All javac levels behave the same.
Comment 5 Maxime Daniel CLA 2006-12-05 04:40:48 EST
Created attachment 55031 [details]
Suggested fix + test cases

Suggested fix (under test) checks if the declaration is within reachable code.
Added test cases for the final locals, for which our behavior was OK.
Comment 6 Maxime Daniel CLA 2006-12-05 06:49:57 EST
Released for 3.3 M4.
Comment 7 Philipe Mulet CLA 2006-12-06 06:25:33 EST
Maxime - pls backport to 3.2.2.
Comment 8 Maxime Daniel CLA 2006-12-07 04:15:06 EST
Released for 3.2.2.
Comment 9 David Audel CLA 2007-01-16 05:00:29 EST
Verified for 3.3M4 with I20061211-1119 by Olivier at 2006-12-11

Verified for 3.2.2 using build M20070112-1200