Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract method refactoring leads to inconsistent code behavior. #3590

Open
DongChunHao opened this issue Apr 25, 2024 · 0 comments
Open

Extract method refactoring leads to inconsistent code behavior. #3590

DongChunHao opened this issue Apr 25, 2024 · 0 comments

Comments

@DongChunHao
Copy link

[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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant