apache / netbeans

Apache NetBeans
https://netbeans.apache.org/
Apache License 2.0
2.64k stars 844 forks source link

[Pull Down Method Refactoring Bug] Pull down method refactoring leads to changes in code calling relationships #7800

Open assdfsdafasfa opened 2 days ago

assdfsdafasfa commented 2 days ago

Apache NetBeans version

Apache NetBeans 23

What happened

When test() is selected to perform pull down refactoring into class A, before refactoring, test() method calls method() of class ParentClass, after refactoring, test() method calls method() of class SubClass, resulting in a change in code behavior.

Code before refactoring

class ParentClass {
void method() {
 System.out.println("ParentClass method");
 }
}
class A extends SubClass { 
void method() {
 System.out.println("Class A method");
 }
}
class SubClass extends ParentClass {
void test() {
 method(); 
 }
}

Language / Project Type / NetBeans Component

No response

How to reproduce

When test() is selected to perform pull down refactoring into class A, before refactoring, test() method calls method() of class ParentClass, after refactoring, test() method calls method() of class SubClass, resulting in a change in code behavior.

Code before refactoring

class ParentClass {
void method() {
 System.out.println("ParentClass method");
 }
}
class A extends SubClass { 
void method() {
 System.out.println("Class A method");
 }
}
class SubClass extends ParentClass {
void test() {
 method(); 
 }
}

Did this work correctly in an earlier version?

No / Don't know

Operating System

Windows11

JDK

20

Apache NetBeans packaging

Apache NetBeans provided installer

Anything else

Code after refactoring

class ParentClass {
void method() {
 System.out.println("ParentClass method");
 }
}
class A extends SubClass { 
void method() {
 System.out.println("Class A method");
 }
void test() {
 method(); 
 }
}
class SubClass extends ParentClass {
}

Are you willing to submit a pull request?

No