Bug 517031 - Refactor Extract Local Variable can't do right when same statements with difference meaning show twice
Summary: Refactor Extract Local Variable can't do right when same statements with diff...
Status: NEW
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.6   Edit
Hardware: PC Windows 10
: P3 enhancement with 1 vote (vote)
Target Milestone: ---   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-05-21 09:23 EDT by Wang Zehao CLA
Modified: 2017-05-21 09:23 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Wang Zehao CLA 2017-05-21 09:23:08 EDT
import java.util.Random;

public class Main {
	public static void main(String[] args) {
1		System.out.println(new Random(1L).nextLong());
2		System.out.println(new Random(1L).nextLong());
	}
}

Above is the target code.
Below is what I did.
1. I select "new Random(1L)" in line 1
2. click Refactor->Extract Local Variable,variable name random

Below is the result of refactoring.

import java.util.Random;

public class Main {
	public static void main(String[] args) {
		Random random = new Random(1L);
		System.out.println(random.nextLong());
		System.out.println(random.nextLong());
	}
}

Below is what I expected.

import java.util.Random;

public class Main {
	public static void main(String[] args) {
		Random random = new Random(1L);
		System.out.println(random.nextLong());
		System.out.println(new Random(1L).nextLong());
	}
}

This refactor change the "new Random(1L)" in line 2 too,so the program will not work correctlly.

Here is the output of this program

before refactoring:

-4964420948893066024
-4964420948893066024

after refactoring:

-4964420948893066024
7564655870752979346

I think this is a very serious bug. It break the correctness of the code