Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 179281

Summary: [extract method] from constructor doesn't handle final members of class
Product: [Eclipse Project] JDT Reporter: Sergey Fukanchik <fukanchik>
Component: UIAssignee: Benjamin Muskalla <b.muskalla>
Status: CLOSED WONTFIX QA Contact:
Severity: normal    
Priority: P3 CC: akiezun, markus.kell.r, zvikico
Version: 3.2   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard: stalebug

Description Sergey Fukanchik CLA 2007-03-26 07:55:12 EDT
Build ID: Build id: M20060629-1905

Steps To Reproduce:
1. Create class with final member and constructor, whith initialisation of final member.
2. "Extract method"
3. You get non-compilable code.


Before:

public class Test {
private final int value;
public Test() {
	value=123;
}
}

After (compiler barks about uninitialised final field):
public class Test {
private final int value;
public Test() {
	bar();
}
private void bar() {
	value=123;
}
}


More information:
Expecting:
Refactoring shall return value from new method and assign it to final variable in constructor.
OR
Refactoring shall scream that it's impossible to extract method if there are several final variables engaged in code being extracted.

Consider example above:

public class Test {
private final int value;
public Test() {
	value = bar();
}
private int bar() {
	return 123;
}
}
Comment 1 Markus Keller CLA 2010-01-25 10:00:22 EST
*** Bug 298294 has been marked as a duplicate of this bug. ***
Comment 2 Markus Keller CLA 2010-01-25 10:00:31 EST
*** Bug 40358 has been marked as a duplicate of this bug. ***
Comment 3 Eclipse Genie CLA 2019-09-15 04:14:08 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.