redhat-developer / redhat-developer/vscode-java

Extract method refactoring leads to inconsistent code behavior.

Open
#3,590 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
2.3k
Forks
546
Avg merge
20h 1m
Merged PRs (30d)
11

Description

[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 "return;"
  2. click “Refacator-Extract to method”

public class OriginalClass {
public void foo() {
Object runnable= null;
Object[] disposeList= null;
for (int i=0; i < disposeList.length; i++) {
if (disposeList [i] == null) {
disposeList [i] = runnable;
// extract method
return;
}
}
}
}

refactoring result:
image

Reason: The extraction method does not contain a return statement. If inline refactoring is performed on the extraction method, the behavior of the statement before and after refactoring is inconsistent.

Expected behavior: Check for statements like return, provide a prompt before refactoring, and do not allow extraction method refactoring.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the case in the Java extension using the supplied OriginalClass example and the listed VS Code and JDK versions. Trace the Extract to method refactoring entry point; done means the refactoring detects the return statement, prompts as appropriate, and does not permit an unsafe extraction.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, typescript, vscode
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.