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

Bug 186253

Summary: [encapsulate field] Encapsulate a referenced field changes behavior
Product: [Eclipse Project] JDT Reporter: kely_garcia <kely_garcia>
Component: UIAssignee: JDT-UI-Inbox <jdt-ui-inbox>
Status: CLOSED WONTFIX QA Contact:
Severity: normal    
Priority: P3    
Version: 3.2.2   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard: stalebug

Description kely_garcia CLA 2007-05-09 16:41:09 EDT
Build ID: M20070212-1330

Steps To Reproduce:
Encapsulate field A.f1 on the following:
class A {
  int f1=3, f2=f1;
  public static void main(String[] args) {
	A a = new A();
	System.out.println("f1: "+ a.f1 + " f2: "+ a.f2);
  }
}

Yields the following refactored code:
class A {
  int f2=getF1();
  private int f1=3;

  public static void main(String[] args) {
   A a = new A();
   System.out.println("f1: "+ a.getF1() + " f2: "+ a.f2);
  }
  void setF1(int f1) {
   this.f1 = f1;
  }
  int getF1() {
   return f1;
  }
}

Note: Before refactoring we get this: f1: 3 f2: 3 and after refactoring we get: f1: 3 f2: 0

More information:
Comment 1 Eclipse Genie CLA 2020-02-23 13:07:21 EST
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. As such, we're closing this bug.

If you have further information on the current state of the bug, please add it and reopen this bug. 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.