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

NullPointerException in onDidCompletionItemSelect #2376

Closed
mfussenegger opened this issue Dec 16, 2022 · 1 comment · Fixed by #2378
Closed

NullPointerException in onDidCompletionItemSelect #2376

mfussenegger opened this issue Dec 16, 2022 · 1 comment · Fixed by #2378
Assignees
Labels

Comments

@mfussenegger
Copy link
Contributor

Using latest master of eclipse.jdt.ls (45f31c1)

As far as I can tell the error only happens when using some snippets:

java.lang.NullPointerException: Cannot invoke "java.util.List.size()" because the return value of "org.eclipse.jdt.ls.core.internal.handlers.CompletionResponse.getItems()" is null
	at org.eclipse.jdt.ls.core.internal.handlers.CompletionHandler.onDidCompletionItemSelect(CompletionHandler.java:137)
	at org.eclipse.jdt.ls.core.internal.JDTDelegateCommandHandler.executeCommand(JDTDelegateCommandHandler.java:152)
	at org.eclipse.jdt.ls.core.internal.handlers.WorkspaceExecuteCommandHandler$1.run(WorkspaceExecuteCommandHandler.java:230)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:45)
	at org.eclipse.jdt.ls.core.internal.handlers.WorkspaceExecuteCommandHandler.executeCommand(WorkspaceExecuteCommandHandler.java:220)
	at org.eclipse.jdt.ls.core.internal.handlers.JDTLanguageServer.lambda$4(JDTLanguageServer.java:561)
	at org.eclipse.jdt.ls.core.internal.BaseJDTLanguageServer.lambda$0(BaseJDTLanguageServer.java:79)
	at java.base/java.util.concurrent.CompletableFuture$UniApply.tryFire(CompletableFuture.java:646)
	at java.base/java.util.concurrent.CompletableFuture$Completion.exec(CompletableFuture.java:483)
	at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:373)
	at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1182)
	at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1655)
	at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1622)
	at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:165)

I can produce this if I write sysout and then trigger completion. The response from the server is:

 {
    result = {
      isIncomplete = false,
      items = { {
          command = {
            arguments = { "1", "0" },
            command = "java.completion.onDidSelect",
            title = ""
          },
          data = {
            COMPLETION_EXECUTION_TIME = "286",
            pid = "0",
            rid = "1",
            uri = "file:///path/to/Example.java"
          },
          detail = "print to standard out",
          insertText = "System.out.println(${0});",
          insertTextFormat = 2,
          kind = 15,
          label = "sysout"
        } }
    }
  } }

If the client then triggers the java.completion.onDidSelect command the exception is raised in:

https://github.com/eclipse/eclipse.jdt.ls/blob/45f31c1f1a940724491d32ced30480e80603d02b/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/handlers/CompletionHandler.java#L137

From what I can tell there are two different CompletionResponse instances in the CompletionResponses cache.

One is set here: https://github.com/eclipse/eclipse.jdt.ls/blob/45f31c1f1a940724491d32ced30480e80603d02b/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/contentassist/SnippetCompletionProposal.java#L324-L325
This one has no items.

The other one here: https://github.com/eclipse/eclipse.jdt.ls/blob/45f31c1f1a940724491d32ced30480e80603d02b/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/contentassist/CompletionProposalRequestor.java#L255
This one would have items, but is not retrieved in the onDidSelect

@testforstephen
Copy link
Contributor

@jdneo for a look.

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

Successfully merging a pull request may close this issue.

3 participants