Inline Method changes behavior for polymorphic method call
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 55/100
- Tipo di issue
- Bug
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Tranquilla
- Stack tecnologico
- java, typescript
- Ambito
- devtools
Direzione di ricerca
La issue non indica alcun file di implementazione né alcun test. Inizia individuando il punto di ingresso del refactoring Inline Method e i relativi test di regressione esistenti, quindi riproduci l’esempio A/B e traccia il modo in cui vengono gestiti i metodi sovrascritti e le chiamate con dispatch dinamico. Il lavoro è completato quando l’operazione viene rifiutata oppure avvisa del cambiamento di comportamento, con un test di regressione che copra gli output 1 e 2.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Description
When using Inline Method on a method that is overridden in a subclass, VS Code Java performs the refactoring successfully, but the refactored program changes its runtime behavior.
The original program relies on dynamic dispatch. After inlining the superclass method body, the polymorphic method call is replaced with a fixed value, which breaks the original behavior.
Steps to reproduce
- Create the following Java code.
- Place the caret on method
fin classA. - Invoke Refactor -> Inline Method.
- Apply the inline refactoring.
- Run the program before and after refactoring.
Original code
package org.example;
public class Main {
public static void main(String[] args) {
A a1 = new A();
A a2 = new B();
a1.test();
a2.test();
}
}
class A {
int f() {
return 1;
}
void test() {
int x = f(); // Inline target
System.out.println(x);
}
}
class B extends A {
@Override
int f() {
return 2;
}
}
Actual behavior
VS Code Java performs the inline refactoring. The refactored program still compiles, but its runtime behavior changes.
Original output:
1
2
Refactored output:
1
1
Refactored code generated by VS Code Java:
package org.example;
public class Main {
public static void main(String[] args) {
A a1 = new A();
A a2 = new B();
a1.test();
a2.test();
}
}
class A {
void test() {
int x = 1;
System.out.println(x);
}
}
class B extends A {
@Override
int f() {
return 2;
}
}
The inline refactoring replaces the polymorphic method call f() with the body of A.f(). However, the call inside A.test() is dynamically dispatched at runtime. When test() is invoked on an instance of B, the original program calls B.f() and prints 2.
After refactoring, this dynamic dispatch is removed, so both calls print 1.
Expected behavior
Inline Method should preserve the runtime behavior of the original program.
The refactoring should either:
- reject the inline operation, or
- report a warning/error indicating that inlining this method may change behavior because the method is overridden and the call is dynamically dispatched.
It should not silently generate behavior-changing code.
- Lingua principale
- TypeScript
- Stelle
- 2.3k
- Fork
- 547
- Merge medio
- 20h 9m
- PR unite (30g)
- 10
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di redhat-developer/vscode-java
-
bug
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 85/100
redhat-developer/vscode-java#4509 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
redhat-developer/vscode-java#4426 ·
-
bug
Difficoltà 4/5 3-5 giorni Idoneità per principianti 45/100
redhat-developer/vscode-java#4506 · 3 commenti · 4 reazioni ·
-
bug
Difficoltà 4/5 3-5 giorni Idoneità per principianti 45/100
redhat-developer/vscode-java#4505 · 2 commenti · 2 reazioni ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 52/100
redhat-developer/vscode-java#4504 · 3 commenti · 1 reazione ·
Tutte le issue di redhat-developer/vscode-java
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
-
bug v2
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
modelcontextprotocol/inspector#2458 · 1 commento ·
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 75/100
railmapgen/rmp-gallery#4068 ·
-
Mend: dependency security vulnerability status: needs triage 🕵️♀️
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
carbon-design-system/ibm-products#9907 ·