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

Bug 356685

Summary: [encapsulate field] introduces a compilation error: Cannot reduce the visibility of the inherited method
Product: [Eclipse Project] JDT Reporter: Gustavo Soares <gsoares>
Component: UIAssignee: JDT-UI-Inbox <jdt-ui-inbox>
Status: CLOSED WONTFIX QA Contact:
Severity: normal    
Priority: P3 CC: markus.kell.r
Version: 3.8   
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard: stalebug

Description Gustavo Soares CLA 2011-09-04 15:31:21 EDT
Build Identifier: 

The encapsulate field refactoring introduces a compilation error in the program. 

Reproducible: Always

Steps to Reproduce:
1. Create the classes
public class A {
  public long getF(){
    return 10;
  }
  public long m(){
    return getF();
  }
}
public class B extends A  {
  public long f;
  public long test(){
    return m();
  }
}
2. Apply the encapsulate field refactoring to f
public class A {
  public long getF(){
    return 10;
  }
  public long m(){
    return getF();
  }
}
public class B extends A  {
  private long f;
  public long test() {
    return m();
  }
  public long getF() {
    return f;
  }
  public long setF(long f) {
    return this.f = f;
  }
}
3. The resulting code does not compile: Cannot reduce the visibility of the inherited method
Comment 1 Gustavo Soares CLA 2011-09-04 15:35:44 EDT
Please do not consider the previous step to reproduce the bug. The correct steps are:  

Steps to Reproduce:
1. Create the classes
public class A {
  public long f;
}
public class B extends A {
  long getF() {
    return 0;
  }
}
2. Apply the encapsulate field refactoring to f
public class A {
  public long f;
  public long getF() {
    return f;
  }
  public void setF(long f) {
    this.f = f;
  }
}
public class B extends A {
  long getF() {
    return 0;
  }  	
}
3. The resulting code does not compile: Cannot reduce the visibility of the
inherited method
Comment 2 Eclipse Genie CLA 2019-12-04 18:40:48 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.

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.