Bug 220777

Summary: [extract method] Extracting a method creates a reference to an uninitialized variable
Product: [Eclipse Project] JDT Reporter: Max Schaefer <xiemaisi>
Component: UIAssignee: JDT-UI-Inbox <jdt-ui-inbox>
Status: NEW --- QA Contact:
Severity: enhancement    
Priority: P3 CC: martinae
Version: 3.3.1   
Target Milestone: ---   
Hardware: PC   
OS: Linux   
Whiteboard:

Description Max Schaefer CLA 2008-02-28 11:48:48 EST
Build ID: M20071023-1652

Steps To Reproduce:
Test case:

    public class A {
      void m() {
        int y;
        int z;
        //from
	try {
	  if(3==3)
	    y = 1;
	  else
	    throw new Exception("boo");
	} catch(Throwable t) {
	  y=2;
	}
	z=y;
        //to
      }
    }
    

If we extract the statements between //from and //to into a method, Eclipse infers the local variable y to be live and passes it as a parameter to the newly created method. In fact, however, y is not live, so the resulting code does not compile due to a violation of the definite assignment restriction.

More information:
Comment 1 Martin Aeschlimann CLA 2008-02-29 06:26:05 EST
I guess this has to do with the implicit initialization to 0 and that y is read later.

Looks like a detail to me. I'm tempted to accept that and set to WONTFIX. Comments?
Comment 2 Max Schaefer CLA 2008-02-29 06:51:06 EST
What do you mean by implicit initialization to 0? y is a local variable, so it is not initialized to anything, right?
Comment 3 Martin Aeschlimann CLA 2008-02-29 07:23:50 EST
You're right...! Have to investigate here...