java-language-server icon indicating copy to clipboard operation
java-language-server copied to clipboard

LS trying to read non-existing file and crashing

Open Ashish-Bansal opened this issue 4 years ago • 2 comments

Hi there,

Server is crashing for me with following output -

16:53:05.246    INFO    LSP connect     Reading messages from queue...
16:53:05.246    INFO    LSP$1MessageReader run  Placing incoming messages on queue...
16:53:05.319    INFO    ScanClassPath jdkTopLevelClasses        Searching for top-level classes in the JDK
16:53:05.460    INFO    ScanClassPath jdkTopLevelClasses        Found 5792 classes in the java platform
Class path:
Doc path:
16:53:05.504    WARNING Docs findSrcZip Couldn't find src.zip in /usr/lib/jvm/java-13-openjdk-amd64
16:53:05.506    INFO    ScanClassPath classPathTopLevelClasses  Searching for top-level classes in 0 classpath locations
16:53:05.511    INFO    ScanClassPath classPathTopLevelClasses  Found 0 classes in classpath
16:53:05.520    INFO    CompletionProvider complete     Complete at RBFoWsC1E7.java(4,11)...
16:53:05.718    WARNING ReusableCompiler getTask        Options changed from [--system, /usr/lib/jvm/java-13-openjdk-amd64, -classpath, , --add-modules, ALL-MODULE-PATH, -proc:none, -g, -Xlint:cast, -Xlint:d$precation, -Xlint:empty, -Xlint:fallthrough, -Xlint:finally, -Xlint:path, -Xlint:unchecked, -Xlint:varargs, -Xlint:static] to [--system, /usr/lib/jvm/java-13-openjdk-amd64, -classpath, , --add-modules, ALL-M$DULE-PATH, -proc:none, -g, -Xlint:cast, -Xlint:deprecation, -Xlint:empty, -Xlint:fallthrough, -Xlint:finally, -Xlint:path, -Xlint:unchecked, -Xlint:varargs, -Xlint:static], creating new compiler
16:53:05.885    WARNING FileStore readInfoFromDisk      /foo/files/RBFoWsC1E7.java
16:53:05.885    SEVERE  LSP connect     null
java.lang.NullPointerException
        at org.javacs.FileStore.packageName(FileStore.java:150)
        at org.javacs.CompileBatch.packageName(CompileBatch.java:79)
        at org.javacs.CompileBatch.needsAdditionalSources(CompileBatch.java:60)
        at org.javacs.JavaCompilerService.doCompile(JavaCompilerService.java:77)
        at org.javacs.JavaCompilerService.loadCompile(JavaCompilerService.java:67)
        at org.javacs.JavaCompilerService.compileBatch(JavaCompilerService.java:93)
        at org.javacs.JavaCompilerService.compile(JavaCompilerService.java:349)
        at org.javacs.completion.CompletionProvider.compileAndComplete(CompletionProvider.java:151)
        at org.javacs.completion.CompletionProvider.complete(CompletionProvider.java:131)
        at org.javacs.JavaLanguageServer.completion(JavaLanguageServer.java:255)
        at org.javacs.lsp.LSP.connect(LSP.java:351)
        at org.javacs.Main.main(Main.java:30)

16:53:06.087    INFO    JavaLanguageServer lint Lint 1 files...
16:53:06.088    SEVERE  Main main       Compiler is already in-use!
java.lang.RuntimeException: Compiler is already in-use!
        at org.javacs.ReusableCompiler.getTask(ReusableCompiler.java:111)
        at org.javacs.CompileBatch.batchTask(CompileBatch.java:105)
        at org.javacs.CompileBatch.<init>(CompileBatch.java:30)
        at org.javacs.JavaCompilerService.doCompile(JavaCompilerService.java:76)
        at org.javacs.JavaCompilerService.loadCompile(JavaCompilerService.java:67)
        at org.javacs.JavaCompilerService.compileBatch(JavaCompilerService.java:93)
        at org.javacs.JavaCompilerService.compile(JavaCompilerService.java:349)
        at org.javacs.JavaCompilerService.compile(JavaCompilerService.java:344)
        at org.javacs.JavaLanguageServer.lint(JavaLanguageServer.java:61)
        at org.javacs.JavaLanguageServer.doAsyncWork(JavaLanguageServer.java:523)
        at org.javacs.lsp.LSP.connect(LSP.java:247)
        at org.javacs.Main.main(Main.java:30)

I'm using openjdk-13-jdk. Here's the full communication between server and client (used socat for exposing server's interface over TCP) -

https://gist.github.com/Ashish-Bansal/61393e82c79c2f74b089854d344d6308

I'm trying to dig into the library and see what's causing this issue. If you can provide any input, it would be really helpful.

Ashish-Bansal avatar Dec 14 '19 17:12 Ashish-Bansal

It's happening because FileStore.packageName tries to read file at that path but didn't find the file on the server.

I feel server shouldn't try to read the file from the server. Reason being, client called textDocument/didOpen and if I understand correctly, client is managing the file now.

According to https://microsoft.github.io/language-server-protocol/overview -

The user opens a file (referred to as a document) in the tool: The tool notifies the language server that a document is open (‘textDocument/didOpen’). From now on, the truth about the contents of the document is no longer on the file system but kept by the tool in memory. The contents now has to be synchronized between the tool and the language server.

Ashish-Bansal avatar Dec 14 '19 18:12 Ashish-Bansal

I created an empty file on the server at that path and it worked fine.

Ashish-Bansal avatar Dec 14 '19 18:12 Ashish-Bansal