Bug 220777 - [extract method] Extracting a method creates a reference to an uninitialized variable
Summary: [extract method] Extracting a method creates a reference to an uninitialized ...
Status: NEW
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.3.1   Edit
Hardware: PC Linux
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: JDT-UI-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-02-28 11:48 EST by Max Schaefer CLA
Modified: 2008-02-29 07:23 EST (History)
1 user (show)

See Also:


Attachments

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