fwcd / kotlin-language-server

Kotlin code completion, diagnostics and more for any editor/IDE using the Language Server Protocol
MIT License
1.62k stars 203 forks source link

Null pointer exception when the language server starts #477

Closed Glyphack closed 6 months ago

Glyphack commented 1 year ago

I get this line whenever language server starts. The lsp still continues to function but this message happens every now and then.

I'm also not sure if the first warning related to SLF4J is related to language server or my system.

[ERROR][2023-06-22 23:41:10] .../vim/lsp/rpc.lua:734    "rpc"   "kotlin-language-server"    "stderr"    "Jun 22, 2023 11:41:10 PM org.eclipse.lsp4j.jsonrpc.services.GenericEndpoint lambda$recursiveFindRpcMethods$2\nSEVERE: A delegate object is null, jsonrpc methods of 'public default org.eclipse.lsp4j.services.NotebookDocumentService org.eclipse.lsp4j.services.LanguageServer.getNotebookDocumentService()' are ignored\n"
[ERROR][2023-06-22 23:41:10] ...lsp/handlers.lua:535    "main      A delegate object is null, jsonrpc methods of 'public default org.eclipse.lsp4j.services.NotebookDocumentService org.eclipse.lsp4j.services.LanguageServer.getNotebookDocumentService()' are ignored"
[ERROR][2023-06-22 23:41:24] .../vim/lsp/rpc.lua:734    "rpc"   "kotlin-language-server"    "stderr"    'Jun 22, 2023 11:41:24 PM org.eclipse.lsp4j.jsonrpc.RemoteEndpoint fallbackResponseError\nSEVERE: Internal error: java.lang.NullPointerException: Cannot invoke "org.eclipse.lsp4j.jsonrpc.messages.Either.getLeft()" because the return value of "org.eclipse.lsp4j.Diagnostic.getCode()" is null\njava.util.concurrent.CompletionException: java.lang.NullPointerException: Cannot invoke "org.eclipse.lsp4j.jsonrpc.messages.Either.getLeft()" because the return value of "org.eclipse.lsp4j.Diagnostic.getCode()" is null\n\tat java.base/java.util.concurrent.CompletableFuture.encodeThrowable(CompletableFuture.java:315)\n\tat java.base/java.util.concurrent.CompletableFuture.completeThrowable(CompletableFuture.java:320)\n\tat java.base/java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1770)\n\tat java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)\n\tat java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)\n\tat java.base/java.lang.Thread.run(Thread.java:833)\nCaused by: java.lang.NullPointerException: Cannot invoke "org.eclipse.lsp4j.jsonrpc.messages.Either.getLeft()" because the return value of "org.eclipse.lsp4j.Diagnostic.getCode()" is null\n\tat org.javacs.kt.codeaction.quickfix.AddMissingImportsQuickFix.getUnresolvedReferencesFromDiagnostics(AddMissingImportsQuickFix.kt:40)\n\tat org.javacs.kt.codeaction.quickfix.AddMissingImportsQuickFix.compute(AddMissingImportsQuickFix.kt:18)\n\tat org.javacs.kt.codeaction.CodeActionKt.getQuickFixes(CodeAction.kt:47)\n\tat org.javacs.kt.codeaction.CodeActionKt.codeActions(CodeAction.kt:23)\n\tat org.javacs.kt.KotlinTextDocumentService$codeAction$1.invoke(KotlinTextDocumentService.kt:95)\n\tat org.javacs.kt.KotlinTextDocumentService$codeAction$1.invoke(KotlinTextDocumentService.kt:93)\n\tat org.javacs.kt.util.AsyncExecutor.compute$lambda$2(AsyncExecutor.kt:19)\n\tat java.base/java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1768)\n\t... 3 more\n\n'
[ERROR][2023-06-22 23:41:24] ...lsp/handlers.lua:535    'async2    Internal error: java.lang.NullPointerException: Cannot invoke "org.eclipse.lsp4j.jsonrpc.messages.Either.getLeft()" because the return value of "org.eclipse.lsp4j.Diagnostic.getCode()" is null'
[ERROR][2023-06-22 23:41:24] ...lsp/handlers.lua:535    'java.util.concurrent.CompletionException: java.lang.NullPointerException: Cannot invoke "org.eclipse.lsp4j.jsonrpc.messages.Either.getLeft()" because the return value of "org.eclipse.lsp4j.Diagnostic.getCode()" is null'
[ERROR][2023-06-22 23:41:24] ...lsp/handlers.lua:535    "\tat java.base/java.util.concurrent.CompletableFuture.encodeThrowable(CompletableFuture.java:315)"
[ERROR][2023-06-22 23:41:24] ...lsp/handlers.lua:535    "\tat java.base/java.util.concurrent.CompletableFuture.completeThrowable(CompletableFuture.java:320)"
[ERROR][2023-06-22 23:41:24] ...lsp/handlers.lua:535    "\tat java.base/java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1770)"
[ERROR][2023-06-22 23:41:24] ...lsp/handlers.lua:535    "\tat java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)"
[ERROR][2023-06-22 23:41:24] ...lsp/handlers.lua:535    "\tat java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)"
[ERROR][2023-06-22 23:41:24] ...lsp/handlers.lua:535    "\tat java.base/java.lang.Thread.run(Thread.java:833)"
[ERROR][2023-06-22 23:41:24] ...lsp/handlers.lua:535    'Caused by: java.lang.NullPointerException: Cannot invoke "org.eclipse.lsp4j.jsonrpc.messages.Either.getLeft()" because the return value of "org.eclipse.lsp4j.Diagnostic.getCode()" is null'
[ERROR][2023-06-22 23:41:24] ...lsp/handlers.lua:535    "\tat org.javacs.kt.codeaction.quickfix.AddMissingImportsQuickFix.getUnresolvedReferencesFromDiagnostics(AddMissingImportsQuickFix.kt:40)"
[ERROR][2023-06-22 23:41:24] ...lsp/handlers.lua:535    "\tat org.javacs.kt.codeaction.quickfix.AddMissingImportsQuickFix.compute(AddMissingImportsQuickFix.kt:18)"
[ERROR][2023-06-22 23:41:24] ...lsp/handlers.lua:535    "\tat org.javacs.kt.codeaction.CodeActionKt.getQuickFixes(CodeAction.kt:47)"
[ERROR][2023-06-22 23:41:24] ...lsp/handlers.lua:535    "\tat org.javacs.kt.codeaction.CodeActionKt.codeActions(CodeAction.kt:23)"
[ERROR][2023-06-22 23:41:24] ...lsp/handlers.lua:535    "\tat org.javacs.kt.KotlinTextDocumentService$codeAction$1.invoke(KotlinTextDocumentService.kt:95)"
[ERROR][2023-06-22 23:41:24] ...lsp/handlers.lua:535    "\tat org.javacs.kt.KotlinTextDocumentService$codeAction$1.invoke(KotlinTextDocumentService.kt:93)"
[ERROR][2023-06-22 23:41:24] ...lsp/handlers.lua:535    "\tat org.javacs.kt.util.AsyncExecutor.compute$lambda$2(AsyncExecutor.kt:19)"
[ERROR][2023-06-22 23:41:24] ...lsp/handlers.lua:535    "\tat java.base/java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1768)"
[ERROR][2023-06-22 23:41:24] ...lsp/handlers.lua:535    "\t... 3 more"

Java version

❯ java -version
openjdk version "17.0.7" 2023-04-18 LTS
OpenJDK Runtime Environment Corretto-17.0.7.7.1 (build 17.0.7+7-LTS)
OpenJDK 64-Bit Server VM Corretto-17.0.7.7.1 (build 17.0.7+7-LTS, mixed mode, sharing)
muhwyndhamhp commented 6 months ago

hey, do you manage to solve this? @Glyphack

Glyphack commented 6 months ago

@muhwyndhamhp No. Sometimes I see exceptions on server start, but they don't affect the functionality of the lsp. I also run JVM 21 now, it might be the reason it was fixed. I also updated the lsp since then. If you faced this issue let me know what is the way to reproduce it but otherwise we can close it since I cannot reproduce it anymore.

openjdk version "21.0.1" 2023-10-17 LTS
muhwyndhamhp commented 6 months ago

I manage to kinda solve it by rebuilding from source mylsef.

But then I cannot get autocomplete / suggestion working.

Go to definition and go to reference working well though.

I'm using on android codebase which currently run on Java 17.

Feel free to close the issue. I'm still figuring out if there's actual fix for the autocomplete issue which seems to be completely different topic.