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

NPE after applying 'Add final modifier for ...' #3274

Open
rgrunber opened this issue Sep 17, 2024 · 0 comments
Open

NPE after applying 'Add final modifier for ...' #3274

rgrunber opened this issue Sep 17, 2024 · 0 comments

Comments

@rgrunber
Copy link
Contributor

Test.java

package test;

public class Test {
	public void foo() {
		String val;
	}
}

Select Add final modifier for 'val' when activating code actions on val. The code action request / subsequent resolve aren't what trigger the error. It's the automatic code action that gets triggered after the final is inserted. That request, ends up at https://github.com/eclipse-jdt/eclipse.jdt.ui/blob/64ae4a641278cc444769d1fe0b04b89d9ba8c297/org.eclipse.jdt.core.manipulation/core%20extension/org/eclipse/jdt/internal/corext/fix/UnusedCodeFixCore.java#L287 as if the binding for val were a type binding, instead of a local variable binding. If code action is re-triggered, it gets recognized correctly as a variable binding. Almost seems like the bindings are not entirely correct immediately after an edit takes place.

Sep. 17, 2024 2:29:08 P.M. org.eclipse.lsp4j.jsonrpc.RemoteEndpoint fallbackResponseError
SEVERE: Internal error: java.lang.NullPointerException: Cannot invoke "org.eclipse.jdt.core.dom.ASTNode.getParent()" because "declaration" is null
java.util.concurrent.CompletionException: java.lang.NullPointerException: Cannot invoke "org.eclipse.jdt.core.dom.ASTNode.getParent()" because "declaration" is null
    at java.base/java.util.concurrent.CompletableFuture.encodeThrowable(Unknown Source)
    at java.base/java.util.concurrent.CompletableFuture.completeThrowable(Unknow
n Source)
    at java.base/java.util.concurrent.CompletableFuture$UniApply.tryFire(Unknown Source)
    at java.base/java.util.concurrent.CompletableFuture$Completion.exec(Unknown Source)
    at java.base/java.util.concurrent.ForkJoinTask.doExec(Unknown Source)
    at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.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.ASTNode.getParent()" because "declaration" is null
    at org.eclipse.jdt.internal.corext.fix.UnusedCodeFixCore$RemoveUnusedMemberOperation.removeUnusedName(UnusedCodeFixCore.java:287)
    at org.eclipse.jdt.internal.corext.fix.UnusedCodeFixCore$RemoveUnusedMemberOperation.rewriteAST(UnusedCodeFixCore.java:268)
    at org.eclipse.jdt.internal.corext.fix.CompilationUnitRewriteOperationsFixCore.createChange(CompilationUnitRewriteOperationsFixCore.java:123)
    at org.eclipse.jdt.ls.core.internal.corrections.proposals.LocalCorrectionsSubProcessor.addUnusedMemberProposal(LocalCorrectionsSubProcessor.java:440)
    at org.eclipse.jdt.ls.core.internal.corrections.QuickFixProcessor.process(QuickFixProcessor.java:346)
    at org.eclipse.jdt.ls.core.internal.corrections.QuickFixProcessor.getCorrections(QuickFixProcessor.java:92)
    at org.eclipse.jdt.ls.core.internal.handlers.CodeActionHandler.getCodeActionCommands(CodeActionHandler.java:189)
    at org.eclipse.jdt.ls.core.internal.handlers.JDTLanguageServer.lambda$14(JDTLanguageServer.java:755)
    at org.eclipse.jdt.ls.core.internal.BaseJDTLanguageServer.lambda$0(BaseJDTLanguageServer.java:87)
    ... 7 more

It's probably easy to fix upstream, but it's an odd way to fail.

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

No branches or pull requests

1 participant