CompletionException - IndexOutOfBoundsException thrown
While trying to recreate code action failure for issue https://github.com/OpenLiberty/liberty-tools-vscode/issues/247 i found following exception.
May 22, 2023 11:00:47 AM org.eclipse.lsp4j.jsonrpc.RemoteEndpoint fallbackResponseError SEVERE: Internal error: java.lang.IndexOutOfBoundsException: Index 0 out of bounds for length 0 java.util.concurrent.CompletionException: java.lang.IndexOutOfBoundsException: Index 0 out of bounds for length 0 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.postComplete(Unknown Source) at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.run(Unknown Source) at java.base/java.lang.Thread.run(Unknown Source) Caused by: java.lang.IndexOutOfBoundsException: Index 0 out of bounds for length 0 at java.base/jdk.internal.util.Preconditions.outOfBounds(Unknown Source) at java.base/jdk.internal.util.Preconditions.outOfBoundsCheckIndex(Unknown Source) at java.base/jdk.internal.util.Preconditions.checkIndex(Unknown Source) at java.base/java.util.Objects.checkIndex(Unknown Source) at java.base/java.util.ArrayList.get(Unknown Source) at org.eclipse.lsp4jakarta.commons.SnippetRegistry.lambda$getCompletionItem$0(SnippetRegistry.java:196) at java.base/java.util.stream.ReferencePipeline$3$1.accept(Unknown Source) at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(Unknown Source) at java.base/java.util.stream.AbstractPipeline.copyInto(Unknown Source) at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(Unknown Source) at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(Unknown Source) at java.base/java.util.stream.AbstractPipeline.evaluate(Unknown Source) at java.base/java.util.stream.ReferencePipeline.collect(Unknown Source) at org.eclipse.lsp4jakarta.commons.SnippetRegistry.getCompletionItem(SnippetRegistry.java:215) at org.eclipse.lsp4jakarta.JakartaTextDocumentService.lambda$completion$2(JakartaTextDocumentService.java:122) ... 4 more
Issue recreated with following env: OS: Windows VSCode version:
Version: 1.78.2 (user setup) Commit: b3e4e68a0bc097f0ae7907b217c1119af9e03435 Date: 2023-05-10T14:39:26.248Z Electron: 22.5.2 Chromium: 108.0.5359.215 Node.js: 16.17.1 V8: 10.8.168.25-electron.0 OS: Windows_NT x64 10.0.19045 Sandboxed: No
Vscode extension: liberty-dev-vscode-ext-0.1.13-SNAPSHOT.vsix Bundles: org.eclipse.lsp4jakarta.jdt.core-0.1.1-SNAPSHOT.jar, org.eclipse.lsp4jakarta.ls-0.1.1-SNAPSHOT-jar-with-dependencies.jar
To recreate: Type in and delete some text inside jakarta specific class.
How pervasive is this error? Does it cause anything to fail?
@cherylking I don't see any functionality affected. But i do see this error only on my windows-10 setup. It doesnt recreate on Mac.
Frequency of the error in windows-10 : 4 to 5 times in 15 minutes of editing on jakarta specific java class.
Mohan will re-test with latest build from @TrevCraw.
Need to determine how pervasive this issue is.
I am unable to reproduce with latest 23.0.6-SNAPSHOT version of vscode binary.
In my testing with VSCode using the latest driver dated May 29th, liberty-dev-vscode-ext-23.0.6-SNAPSHOT.vsix, I was not able to recreate this exception.
Curiously, I was able to recreate this on Mac with the 23.0.6-SNAPSHOT.
I used the jakarta-sample project, app name jakarta-servlet, found in this repo under jakarta.jdt/org.eclipse.lsp4jakarta.jdt.test/projects. I went to any file under the annotations dir. No changes were necessary.
Here I see some diagnostics and code completion works fine.
Going up two levels and opening the dir from jakarta.jdt ...
Diagnostics vanish and triggering code completion produces this error.
Text copy here:
May 31, 2023 3:37:03 PM org.eclipse.lsp4jakarta.JakartaTextDocumentService lambda$completion$1
SEVERE: Return LSP4Jakarta getContextBasedFilter() from client did not succeed: org.eclipse.lsp4j.jsonrpc.ResponseErrorException: Request jakarta/java/classpath failed with message: java.lang.NullPointerException: Cannot invoke "org.eclipse.jdt.core.ICompilationUnit.getJavaProject()" because "unit" is null
May 31, 2023 3:37:03 PM org.eclipse.lsp4j.jsonrpc.RemoteEndpoint fallbackResponseError
SEVERE: Internal error: java.lang.IndexOutOfBoundsException: Index 6 out of bounds for length 1
java.util.concurrent.CompletionException: java.lang.IndexOutOfBoundsException: Index 6 out of bounds for length 1
@dshimo could you please post the whole stacktrace? The stacktrace looks a bit different from the original reported exception.
I realize the approach was wildly different from mohlogan's and may be an entirely different issue as I was not able to reproduce vscode#247
Here's the stacktrace regardless,
SEVERE: Return LSP4Jakarta getContextBasedFilter() from client did not succeed: org.eclipse.lsp4j.jsonrpc.ResponseErrorException: Request jakarta/java/classpath failed with message: java.lang.NullPointerException: Cannot invoke "org.eclipse.jdt.core.ICompilationUnit.getJavaProject()" because "unit" is null
Jun 01, 2023 9:51:47 AM org.eclipse.lsp4j.jsonrpc.RemoteEndpoint fallbackResponseError
SEVERE: Internal error: java.lang.IndexOutOfBoundsException: Index 6 out of bounds for length 1
java.util.concurrent.CompletionException: java.lang.IndexOutOfBoundsException: Index 6 out of bounds for length 1
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.biApply(Unknown Source)
at java.base/java.util.concurrent.CompletableFuture$BiApply.tryFire(Unknown Source)
at java.base/java.util.concurrent.CompletableFuture$Completion.exec(Unknown Source)
at java.base/java.util.concurrent.ForkJoinTask.doExec(Unknown Source)
at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(Unknown Source)
at java.base/java.util.concurrent.ForkJoinPool.scan(Unknown Source)
at java.base/java.util.concurrent.ForkJoinPool.runWorker(Unknown Source)
at java.base/java.util.concurrent.ForkJoinWorkerThread.run(Unknown Source)
Caused by: java.lang.IndexOutOfBoundsException: Index 6 out of bounds for length 1
at java.base/jdk.internal.util.Preconditions.outOfBounds(Unknown Source)
at java.base/jdk.internal.util.Preconditions.outOfBoundsCheckIndex(Unknown Source)
at java.base/jdk.internal.util.Preconditions.checkIndex(Unknown Source)
at java.base/java.util.Objects.checkIndex(Unknown Source)
at java.base/java.util.ArrayList.get(Unknown Source)
at org.eclipse.lsp4jakarta.commons.snippets.SnippetRegistry.lambda$getCompletionItem$1(SnippetRegistry.java:198)
at java.base/java.util.stream.ReferencePipeline$3$1.accept(Unknown Source)
at java.base/java.util.stream.ReferencePipeline$2$1.accept(Unknown Source)
at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(Unknown Source)
at java.base/java.util.stream.AbstractPipeline.copyInto(Unknown Source)
at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(Unknown Source)
at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(Unknown Source)
at java.base/java.util.stream.AbstractPipeline.evaluate(Unknown Source)
at java.base/java.util.stream.ReferencePipeline.collect(Unknown Source)
at org.eclipse.lsp4jakarta.commons.snippets.SnippetRegistry.getCompletionItem(SnippetRegistry.java:217)
at org.eclipse.lsp4jakarta.JakartaTextDocumentService.lambda$completion$3(JakartaTextDocumentService.java:145)
... 8 more
We made a fix related to this, the one that fixed the package name and class name of a snippet. Could you ensure you are using the latest lsp4jakarta?