Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 320046 - Fails to detect that a local variable is always initialized.
Summary: Fails to detect that a local variable is always initialized.
Status: VERIFIED DUPLICATE of bug 318020
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.7   Edit
Hardware: Macintosh Mac OS X - Carbon (unsup.)
: P3 normal (vote)
Target Milestone: 3.6.1   Edit
Assignee: Ayushman Jain CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-07-15 17:38 EDT by Richard CLA
Modified: 2010-08-26 02:51 EDT (History)
2 users (show)

See Also:


Attachments

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