Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 320046

Summary: Fails to detect that a local variable is always initialized.
Product: [Eclipse Project] JDT Reporter: Richard <unp1>
Component: CoreAssignee: Ayushman Jain <amj87.iitr>
Status: VERIFIED DUPLICATE QA Contact:
Severity: normal    
Priority: P3 CC: Olivier_Thomann, srikanth_sankaran
Version: 3.7   
Target Milestone: 3.6.1   
Hardware: Macintosh   
OS: Mac OS X - Carbon (unsup.)   
Whiteboard:

Description Richard CLA 2010-07-15 17:38:18 EDT
Build Identifier: I20100608-0911

The flow analysis from the compiler does not recognize that in that case

public class Test {

    public static void main(String[] args) {
	    Integer tmp;
	    tmp = new Integer(5);
	    Object o;
	    if (tmp instanceof Integer)
	    {
	        o = (Integer)tmp;
	    }
	    else
	    {
	        {if (true) throw new RuntimeException();}
	    }
	    System.out.println(o);
    }
 }

o will always be initialized when reaching the System.out.println statement. I think that this may strictly spoken not be bug as the JLS would allow to classify it as error, but previous eclipse versions compile the code without complaint. 

[[The actual problem occurs for me in generated code and has to be "work-arounded" each time.]]

Reproducible: Always

Steps to Reproduce:
1.Compiling class 
public class Test {

    public static void main(String[] args) {
	    Integer tmp;
	    tmp = new Integer(5);
	    Object o;
	    if (tmp instanceof Integer)
	    {
	        o = (Integer)tmp;
	    }
	    else
	    {
	        {if (true) throw new RuntimeException();}
	    }
	    System.out.println(o);
    }
    
}
in eclipse 3.6 fails with the error message "o may not be initialised", but works fine with (at least) eclipse 3.5 
2.
3.
Comment 1 Olivier Thomann CLA 2010-07-15 20:51:08 EDT
Looks like a dup of bug 318020.
Ayushman, I let you check it. If a dup, please release the fix for 318020.
Comment 2 Ayushman Jain CLA 2010-07-17 14:29:46 EDT
Thanks Olivier, this is the same as 318020.

*** This bug has been marked as a duplicate of bug 318020 ***
Comment 3 Srikanth Sankaran CLA 2010-08-03 07:44:06 EDT
Verified for 3.7 M1 using build I20100802-1800
Comment 4 Srikanth Sankaran CLA 2010-08-26 02:51:25 EDT
Verified for 3.6.1 RC2 using Build id: M20100825-0800