eclipse.jdt.ls icon indicating copy to clipboard operation
eclipse.jdt.ls copied to clipboard

NPE due to null context.getCoveringNode() in SourceAssistProcessor.getSourceActionCommands

Open jypma opened this issue 1 year ago • 1 comments

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.

jypma avatar Nov 05 '24 10:11 jypma

So basically context.getCoveringNode() is null at https://github.com/eclipse-jdtls/eclipse.jdt.ls/blob/f155e1fc90618b558899c3722606feccfc89e210/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/text/correction/SourceAssistProcessor.java#L123 . The implementation is

https://github.com/eclipse-jdtls/eclipse.jdt.ls/blob/f155e1fc90618b558899c3722606feccfc89e210/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/corrections/InnovationContext.java#L83-L88 (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.

rgrunber avatar Nov 07 '24 17:11 rgrunber