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 due to null context.getCoveringNode() in SourceAssistProcessor.getSourceActionCommands #3318

Open
jypma opened this issue Nov 5, 2024 · 1 comment

Comments

@jypma
Copy link

jypma commented Nov 5, 2024

I'm getting the following stack trace when invoking a code assist (from emacs lsp as client):

Caused by: java.lang.NullPointerException: Cannot invoke "org.eclipse.jdt.core.dom.ASTNode.accept(org.eclipse.jdt.core.dom.ASTVisitor)" because "coveringNode" is null
	at org.eclipse.jdt.ls.core.internal.text.correction.QuickAssistProcessor.getFullyCoveredNodes(QuickAssistProcessor.java:391)
	at org.eclipse.jdt.ls.core.internal.text.correction.SourceAssistProcessor.getSourceActionCommands(SourceAssistProcessor.java:123)
	at org.eclipse.jdt.ls.core.internal.handlers.CodeActionHandler.getCodeActionCommands(CodeActionHandler.java:241)
	at org.eclipse.jdt.ls.core.internal.handlers.JDTLanguageServer.lambda$14(JDTLanguageServer.java:758)

Apparently context in SourceAssistProcessor has a null converingNode. This happens in almost all cases I try to use code assist.

This is on 1.41.0 (but also occurred before).

Unfortunately I don't have a minimal reproducer to share, since I can't share the project source code, and have not encountered the issue in other projects.

@rgrunber
Copy link
Contributor

rgrunber commented Nov 7, 2024

So basically context.getCoveringNode() is null at

ArrayList<ASTNode> coveredNodes = QuickAssistProcessor.getFullyCoveredNodes(context, context.getCoveringNode());
. The implementation is

public ASTNode getCoveringNode() {
if (fNodeFinder == null) {
fNodeFinder = new NodeFinder(getASTRoot(), fSelectionOffset, fSelectionLength);
}
return fNodeFinder.getCoveringNode();
}
(yeah, that's quite the typo for the class name but it can be fixed later).

This is likely happening in textDocument/codeAction requests, so if you could look in your language server logs and determine what the request document is, and what the cursor/selection range position is when this happens, it might help you narrow it down to some block of code, which can hopefully be reproduced.

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

2 participants