redhat-developer / vscode-java

Java Language Support for Visual Studio Code
Eclipse Public License 2.0
2.07k stars 433 forks source link

Renaming methods causes code behavior to change #3705

Open DongChunHao opened 2 months ago

DongChunHao commented 2 months ago

[provide a description of the issue]

Environment

Operating System: Windows11 JDK version: 17 Visual Studio Code version: 1.88 Java extension version: 1.29

Steps To Reproduce
  1. select "k()"
  2. click "Refactor-Rename"
  3. new method name "m()"

In this example, before the rename, the f() method calls the m() method in the parent class, and after the rename, the f() method calls the method in the subclass renamed m(). The rename causes the code behavior to change, so it is a bug.

class A { void m(Object m){ System.out.println("A"); } } class B extends A{ // rename k to m void k(String m){ System.out.println("B"); } void f(){ m("1"); } }

Current Result:

image

Expected Result: A warning is given during the refactoring process that the name may cause the refactoring behavior to change
Additional Informations