eclipse-jdt / eclipse.jdt.ui

Eclipse Public License 2.0
36 stars 86 forks source link

Bug: Move method refactoring causes changes in code behavior #1517

Closed DongChunHao closed 1 month ago

DongChunHao commented 1 month ago

Select the m() method in class A and reconstruct the moving method into class B. As a result, class C.m() is called in the method() method in class D before refactoring, and B.m() is called after refactoring, and the code behavior changes. The code before refactoring is as follows:

image

The resulting code after refactoring is as follows:

image

DongChunHao commented 1 month ago

@jjohnstn Please help me to confirm whether this is a bug, thank you

jjohnstn commented 1 month ago

@DongChunHao It is a definite behavior change. The question is whether the code should prevent you from all harm or whether it is doing what you asked it to do and there may be consequences. It often depends on how common the scenario is and how efficiently it can be detected. In this case it would require finding all extenders of B and their subclasses that reference a method m() from an outer class. I will take a look.

jjohnstn commented 1 month ago

@DongChunHao I was able to create a fix that seems to perform reasonably.