Bug 3821 - Refactoring - variable extraction can lead to incorrect code (1GEWDNW)
Summary: Refactoring - variable extraction can lead to incorrect code (1GEWDNW)
Status: RESOLVED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 2.0   Edit
Hardware: All Windows NT
: P2 major (vote)
Target Milestone: ---   Edit
Assignee: Dirk Baeumer CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2001-10-10 23:01 EDT by Philipe Mulet CLA
Modified: 2002-01-21 08:11 EST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Philipe Mulet CLA 2001-10-10 23:01:26 EDT
Extracting to method the code in between /*START*/ and /*END*/ results in invalid source:

package p1;

import java.io.*;
public class X {
	void foo(final int out){
		int i;
		if (out > 5){
			/*START*/i = 1;/*END*/
		} else {
			i = 2;
		}
		i++;
	}
}

=====>

package p1;

import java.io.*;
public class X {
	void foo(final int out){
		int i;
		if (out > 5){
			i = asd(i);	// COMPLAINS THAT VARIABLE 'i' MAY NOT HAVE BEEN INITIALIZED - diagnosis is correct
		} else {
			i = 2;
		}
		i++;
	}
	protected int asd(int i) {
		i = 1;
		System.out.println(i);
		return i;
	}
}

NOTES:

DB (06.06.2001 14:23:42)
	The only way to fix this is to generate the extracted method as follows:

	protected int asd() {
		return 1;
	}

	Impact of this fix on extract method is high, since we have to do some analysis for the extracted method.

	Opt to not fix this for June.
Comment 1 Martin Aeschlimann CLA 2001-10-16 11:13:21 EDT
moved to 'active'
Comment 2 DJ Houghton CLA 2001-10-24 07:21:40 EDT
PRODUCT VERSION:
SDK 119

Comment 3 Erich Gamma CLA 2001-11-11 05:47:02 EST
works for me in the latest
Comment 4 Andre Weinand CLA 2002-01-18 04:41:44 EST
20020115: Now, by extracting "i = 1;" I get

package p1;

import java.io.*;
public class X {
	void foo(final int out){
		int i;
		if (out > 5){
			asd();
		} else {
			i = 2;
		}
		i++;
	}
	protected void asd() {
		int i;
		i = 1;
	}
}

asd() doesn't do anything useful and it changes the behaviour of foo.
Comment 5 Andre Weinand CLA 2002-01-18 04:43:45 EST
See previous comment
Comment 6 Dirk Baeumer CLA 2002-01-21 08:11:21 EST
Fixed in build > iX-20021115