lsp4jakarta icon indicating copy to clipboard operation
lsp4jakarta copied to clipboard

CompletionException - IndexOutOfBoundsException thrown

Open mohlogan opened this issue 2 years ago • 9 comments

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.

mohlogan avatar May 23 '23 12:05 mohlogan

How pervasive is this error? Does it cause anything to fail?

cherylking avatar May 23 '23 16:05 cherylking

@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.

mohlogan avatar May 24 '23 12:05 mohlogan

Mohan will re-test with latest build from @TrevCraw.

Need to determine how pervasive this issue is.

yeekangc avatar May 29 '23 13:05 yeekangc

I am unable to reproduce with latest 23.0.6-SNAPSHOT version of vscode binary.

mohlogan avatar May 30 '23 13:05 mohlogan

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.

rumanaHaque avatar May 31 '23 16:05 rumanaHaque

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. image

Going up two levels and opening the dir from jakarta.jdt ... Diagnostics vanish and triggering code completion produces this error. image

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 avatar May 31 '23 20:05 dshimo

@dshimo could you please post the whole stacktrace? The stacktrace looks a bit different from the original reported exception.

TrevCraw avatar Jun 01 '23 04:06 TrevCraw

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

dshimo avatar Jun 01 '23 15:06 dshimo

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?

turkeylurkey avatar Jun 05 '23 01:06 turkeylurkey