Repository navigation
Closed
Labels
for: eclipsesomething that is specific for Eclipsefor: vscodesomething that is specific for VSCodestatus: needs-investigationtheme: internal-architecturetype: bug
Milestone
Description
Applied a Spring Boot upgrade, then quickly closed a bunch of open editors. Popup appears, showing an error for textDocument/definition:
java.util.concurrent.CompletionException: java.lang.NullPointerException: Cannot invoke "org.eclipse.jdt.core.dom.CompilationUnit.getPosition(int, int)" because "cu" is null
at java.base/java.util.concurrent.CompletableFuture.encodeThrowable(Unknown Source)
at java.base/java.util.concurrent.CompletableFuture.completeThrowable(Unknown Source)
at java.base/java.util.concurrent.CompletableFuture$UniApply.tryFire(Unknown Source)
at java.base/java.util.concurrent.CompletableFuture$Completion.run(Unknown Source)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.base/java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NullPointerException: Cannot invoke "org.eclipse.jdt.core.dom.CompilationUnit.getPosition(int, int)" because "cu" is null
at org.springframework.ide.vscode.boot.java.JavaDefinitionHandler.lambda$handle$0(JavaDefinitionHandler.java:60)
at org.springframework.ide.vscode.boot.java.utils.CompilationUnitCache.withCompilationUnit(CompilationUnitCache.java:237)
at org.springframework.ide.vscode.boot.java.JavaDefinitionHandler.handle(JavaDefinitionHandler.java:58)
at org.springframework.ide.vscode.languageserver.starter.LanguageServerAutoConf.lambda$registerDefinitionHandler$2(LanguageServerAutoConf.java:97)
at org.springframework.ide.vscode.commons.languageserver.util.SimpleTextDocumentService.lambda$definition$6(SimpleTextDocumentService.java:371)
... 5 more
Metadata
Metadata
Assignees
Labels
for: eclipsesomething that is specific for Eclipsefor: vscodesomething that is specific for VSCodestatus: needs-investigationtheme: internal-architecturetype: bug
Activity
martinlippert commentedon Feb 2, 2024
another exception found in the log in the same area, but not related to the
textDocument/definitionrequest:martinlippert commentedon Feb 2, 2024
Further analysis for the second case:
This seems to happen sometime before:
which is followed by:
then:
It looks suspicious that those exceptions are being thrown (looks like the parser can't do its job), but then a
Parsed successfullymessage appears. Maybe there is an entry put into the cache even in case that there was an exception during parsing (and no CU has been produced), so that trying to use the entry in the cache later on results in further errors, like the exception mentioned above (NPE).martinlippert commentedon Feb 9, 2024
Ok, I think I know what is going on here. The high level summary is:
CompilationUnitCachekeeps a cache ofCompletableFutureobjects, not theCompilationUnitobjects directly.CompilationUnit(the AST basically) - and this future is being put into the cacheNow, the parsing itself throws a bunch of exceptions internally (due to various reasons, but things like that could happen anytime, especially because parallel things could happen anytime, like a local maven build removing JARs from disc that belonged to the classpath, source files being deleted, whatever). There is no way to ensure that the parsing will succeed, so we need to deal with the failure situation.
At the moment, the cache keeps the
CompletableFuture, even if the computation of the AST failed and therefore the result of the future is null. So on future invocations of theCompilationUnitCache, the.get()call on the future will returnnull. It looks like - in that case - the requestors apply method is not being invoked withnull, just nothing happens - which is strange, since the feature that is invoking this will just not work and will not directly recover.On an additional note, if the
projectobject that is passed into theCompilationUnitCacheisnull, the requestor will be invoked withnullfor theCompilationUnit, which might cause the above mentioned exceptions in theSpringIndexerJavaor theJavaDefinitionHandler.I think we need to do two things here:
CompilationUnitCachesafe forCompilationUnitobjects that are nullCompletableFutureobjects, if the parsing fails, so that the cache will recover automatically and try again next time.There might still be the case where the user of the CompilationUnitCache gets a
nullback and therefore the functionality is broken, but gets a valid object the next time it invokes the cache. Interesting question how to improve this situation as well.(cc. @BoykoAlex )
BoykoAlex commentedon Feb 9, 2024
Perhaps completing the CU future exceptionally and then if it has completed exceptionally chain something to the future to invalidate the cache entry...
BoykoAlex commentedon Feb 16, 2024
Here is the branch with a candidate fix: https://github.com/spring-projects/sts4/tree/cu-cache-fix
I have tried artificial exception with combination of time consuming parsing with
THROTTLEandDEBOUNCEreconcile strategy. Seemed to work so far...BoykoAlex commentedon Mar 6, 2024
Lets try the fix: 4ce4f02 - seems harmless and likely to help with the issue above