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

Cannot refactor in static init #2370

Closed
Nightenom opened this issue Mar 21, 2022 · 1 comment · Fixed by eclipse-jdtls/eclipse.jdt.ls#2049
Closed

Cannot refactor in static init #2370

Nightenom opened this issue Mar 21, 2022 · 1 comment · Fixed by eclipse-jdtls/eclipse.jdt.ls#2049

Comments

@Nightenom
Copy link

As shown in the picture below, refactor actions are not available in static init.

Environment
  • Operating System: Windows_NT x64 10.0.19043
  • JDK version: OpenJDK Runtime Environment Temurin-17.0.1+12 (build 17.0.1+12)
  • Visual Studio Code version: 1.65.2
  • Java extension version: v1.4.0
Steps To Reproduce
  1. Create a class with static method and static init and fill them with longer expressions.
  2. Try to refactor in static method - see it works
  3. Try to refactor in static init - see it doesn't work

Hopefully, no logs are needed, reproducible in many environments.

Current Result

Refactor actions are not available in static init.

Expected Result

Refactor actions are available in static init.

Additional Informations

Compiled pictures of using refactor action on both places.
image

@rgrunber
Copy link
Member

This should be a simple change. @snjeza's change is simply catching an error that failed the entire code action collection in the static initializer case.

[Trace - 2:41:03 PM] Received response 'textDocument/codeAction - (444)' in 69ms. Request failed: Internal error. (-32603).
Error data: "java.util.concurrent.CompletionException: java.lang.NullPointerException: Cannot invoke \"org.eclipse.jdt.core.dom.MethodDeclaration.getParent()\" because the return value of \"org.eclipse.jdt.ls.core.internal.corext.refactoring.code.ExtractFieldRefactoring.getMethodDeclaration()\" is null
	at java.base/java.util.concurrent.CompletableFuture.encodeThrowable(Unknown Source)
	at java.base/java.util.concurrent.CompletableFuture.completeThrowable(Unknown Source)
	at java.base/java.util.concurrent.CompletableFuture.tryFire(Unknown Source)
	at java.base/java.util.concurrent.CompletableFuture.exec(Unknown Source)
	at java.base/java.util.concurrent.ForkJoinTask.doExec(Unknown Source)
	at java.base/java.util.concurrent.ForkJoinPool.topLevelExec(Unknown Source)
	at java.base/java.util.concurrent.ForkJoinPool.scan(Unknown Source)
	at java.base/java.util.concurrent.ForkJoinPool.runWorker(Unknown Source)
	at java.base/java.util.concurrent.ForkJoinWorkerThread.run(Unknown Source)
Caused by: java.lang.NullPointerException: Cannot invoke \"org.eclipse.jdt.core.dom.MethodDeclaration.getParent()\" because the return value of \"org.eclipse.jdt.ls.core.internal.corext.refactoring.code.ExtractFieldRefactoring.getMethodDeclaration()\" is null
	at org.eclipse.jdt.ls.core.internal.corext.refactoring.code.ExtractFieldRefactoring.getEnclosingTypeDeclaration(ExtractFieldRefactoring.java:888)
	at org.eclipse.jdt.ls.core.internal.corext.refactoring.code.ExtractFieldRefactoring.checkInitialConditions(ExtractFieldRefactoring.java:315)
	at org.eclipse.jdt.ls.core.internal.text.correction.RefactorProposalUtility.getExtractFieldProposal(RefactorProposalUtility.java:556)
	at org.eclipse.jdt.ls.core.internal.text.correction.RefactorProposalUtility.getGenericExtractFieldProposal(RefactorProposalUtility.java:527)
	at org.eclipse.jdt.ls.core.internal.corrections.RefactorProcessor.getExtractFieldProposal(RefactorProcessor.java:295)
	at org.eclipse.jdt.ls.core.internal.corrections.RefactorProcessor.getProposals(RefactorProcessor.java:140)
	at org.eclipse.jdt.ls.core.internal.handlers.CodeActionHandler.getCodeActionCommands(CodeActionHandler.java:177)
	at org.eclipse.jdt.ls.core.internal.handlers.JDTLanguageServer.lambda5(JDTLanguageServer.java:666)
	at org.eclipse.jdt.ls.core.internal.BaseJDTLanguageServer.lambdabash(BaseJDTLanguageServer.java:75)
	... 7 more

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

Successfully merging a pull request may close this issue.

3 participants