eclipse-jdtls / eclipse.jdt.ls

Java language server
1.8k stars 400 forks source link

NPE in CodeActionHandler.getProblemId L.221 #1502

Closed apupier closed 4 years ago

apupier commented 4 years ago
[Error - 11:06:09 AM] Request textDocument/codeAction failed.
  Message: Internal error.
  Code: -32603 
java.util.concurrent.CompletionException: java.lang.NullPointerException
    at java.util.concurrent.CompletableFuture.encodeThrowable(CompletableFuture.java:273)
    at java.util.concurrent.CompletableFuture.completeThrowable(CompletableFuture.java:280)
    at java.util.concurrent.CompletableFuture.uniApply(CompletableFuture.java:618)
    at java.util.concurrent.CompletableFuture$UniApply.tryFire(CompletableFuture.java:591)
    at java.util.concurrent.CompletableFuture$Completion.exec(CompletableFuture.java:457)
    at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
    at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
    at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
    at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)
Caused by: java.lang.NullPointerException
    at org.eclipse.jdt.ls.core.internal.handlers.CodeActionHandler.getProblemId(CodeActionHandler.java:221)
    at org.eclipse.jdt.ls.core.internal.handlers.CodeActionHandler.getProblemLocationCores(CodeActionHandler.java:209)
    at org.eclipse.jdt.ls.core.internal.handlers.CodeActionHandler.getCodeActionCommands(CodeActionHandler.java:94)
    at org.eclipse.jdt.ls.core.internal.handlers.JDTLanguageServer.lambda$14(JDTLanguageServer.java:638)
    at org.eclipse.jdt.ls.core.internal.BaseJDTLanguageServer.lambda$0(BaseJDTLanguageServer.java:75)
    at java.util.concurrent.CompletableFuture.uniApply(CompletableFuture.java:616)
    ... 6 more

curent content fo the file:

// camel-k: trait=3scale.auto=false trait=3scale.auto=true

import org.apache.camel.builder.RouteBuilder;

public class Simple extends RouteBuilder {
  @Override
  public void configure() throws Exception {

      // Write your routes here, for example:
      from("direct:xx")
  .to("http://quarkus-ml.{{env:NAMESPACE}}.svc.cluster.local/samples")
  //.to("netty-http:http://quarkus-ml.{{env:NAMESPACE}}.svc.cluster.local/samples");

  }
}

it seems to be when there is a diagnostic on th file which is provided by anothe rLanguage Server. In this case, you will need to install https://marketplace.visualstudio.com/items?itemName=redhat.vscode-apache-camel to reproduce with provided file inside VS Code

apupier commented 4 years ago
[Trace - 11:09:37 AM] Sending request 'textDocument/codeAction - (128)'.
Params: {
    "textDocument": {
        "uri": "file:///home/apupier/ws/camelk-test/Simple.java"
    },
    "range": {
        "start": {
            "line": 0,
            "character": 23
        },
        "end": {
            "line": 0,
            "character": 23
        }
    },
    "context": {
        "diagnostics": [
            {
                "range": {
                    "start": {
                        "line": 0,
                        "character": 18
                    },
                    "end": {
                        "line": 0,
                        "character": 35
                    }
                },
                "message": "More than one trait defines the same property: 3scale.auto",
                "severity": 1
            }
        ]
    }
}

I think it should check if there is a code or not. Based on specification the code is not mandatory https://microsoft.github.io/language-server-protocol/specification#diagnostic

code?: number | string;
fbricon commented 4 years ago

Fixed with #1503