Bug 235546

Summary: [compiler] different behavior than javac on definite assignment analysis involving infinite loop
Product: [Eclipse Project] JDT Reporter: Maxime Daniel <maxime_daniel>
Component: CoreAssignee: JDT-Core-Inbox <jdt-core-inbox>
Status: VERIFIED INVALID QA Contact:
Severity: normal    
Priority: P3    
Version: 3.4   
Target Milestone: 3.4 RC4   
Hardware: PC   
OS: All   
Whiteboard:

Description Maxime Daniel CLA 2008-06-04 03:57:31 EDT
I20080530-1730

On the following code, javac reports an error while Eclipse does not:

public class X {
  public static void main(String args[]) {
	final int i;
	for (;true;) {
	  if (true) {
		break;
	  } else {
		i = 0;
	  }
	}
	i = 1; // javac reports an error here
  }
}
Comment 1 Maxime Daniel CLA 2008-06-04 04:01:08 EDT
Following JL3 §16, i is definitely unassigned before the second assignment iff it is so after true when false and before the only break that branches to the for statement. I believe that both conditions hold true, giving us right and javac wrong.
Closing as INVALID.
Comment 2 Maxime Daniel CLA 2008-06-04 08:41:22 EDT
Added AssignmentTest#56 and 57.
Comment 3 Frederic Fusier CLA 2008-06-06 10:24:52 EDT
Agreed that 'i' is definitely unassigned in this case reading the following rule in chapter JLS3 §16.2.12:
  . V is [un]assigned after a for statement iff both of the following are true:
    + Either a condition expression is not present or V is [un]assigned after
      the condition expression when false.
    + V is [un]assigned before every break statement for which the for statement
      is the break target.