Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Repeated "Request textDocument/codeAction failed" errors #247

Closed
TrevCraw opened this issue May 7, 2023 · 17 comments · Fixed by #255
Closed

Repeated "Request textDocument/codeAction failed" errors #247

TrevCraw opened this issue May 7, 2023 · 17 comments · Fixed by #255
Assignees
Labels
bug Something isn't working must-fix
Milestone

Comments

@TrevCraw
Copy link
Contributor

TrevCraw commented May 7, 2023

When working in Java files while LSP4Jakarta is activated, attention is constantly pulled to the Output tab as there are repeated codeAction request failures. These errors do not appear to affect the language feature functionality, but they do pull the user's focus and repeatedly show up in the log.

May 07, 2023 5:57:19 P.M. org.eclipse.lsp4jakarta.commons.JakartaEESnippetRegistryLoader load
INFO: Loading snippets into registry...
May 07, 2023 5:57:19 P.M. org.eclipse.lsp4jakarta.JakartaLanguageServer initialize
INFO: Initializing Jakarta EE server
[Error - 6:00:11 PM] Request textDocument/codeAction failed.
  Message: The request (id: 10, method: 'textDocument/codeAction') has been cancelled
  Code: -32800 
[Error - 6:05:00 PM] Request textDocument/codeAction failed.
  Message: The request (id: 108, method: 'textDocument/codeAction') has been cancelled
  Code: -32800 
[Error - 6:05:11 PM] Request textDocument/codeAction failed.
  Message: The request (id: 130, method: 'textDocument/codeAction') has been cancelled
  Code: -32800 
[Error - 6:07:21 PM] Request textDocument/codeAction failed.
  Message: The request (id: 258, method: 'textDocument/codeAction') has been cancelled
  Code: -32800 

Another version of the codeAction failure resulted in an NPE:

[Error - 6:15:15 PM] Request textDocument/codeAction failed.
  Message: Request jakarta/java/codeaction failed with message: java.lang.NullPointerException: Cannot invoke "java.util.Collection.toArray()" because "<parameter1>" is null
  Code: -32603

It was initially thought that the codeAction failures were related to the NPE in #227 (you can see the codeAction failures in the log for that issue) or the UnsupportedOperationException in #207, but it seems they may be an issue on their own. It is not clear if the root cause of the issue resides on the VS Code client side or on the language server side.

@TrevCraw TrevCraw added bug Something isn't working must-fix labels May 7, 2023
@TrevCraw TrevCraw added this to the GA milestone May 7, 2023
@TrevCraw
Copy link
Contributor Author

TrevCraw commented May 11, 2023

Ran into a couple more errors:

[Error - 9:53:02 AM] Request textDocument/codeAction failed.

  Message: Request jakarta/java/codeaction failed with message: java.lang.ClassCastException: class org.eclipse.jdt.core.dom.TypeDeclaration cannot be cast to class org.eclipse.jdt.core.dom.MethodDeclaration (org.eclipse.jdt.core.dom.TypeDeclaration and org.eclipse.jdt.core.dom.MethodDeclaration are in unnamed module of loader org.eclipse.osgi.internal.loader.EquinoxClassLoader @25107054)

  Code: -32603
May 11, 2023 9:59:00 A.M. org.eclipse.lsp4j.jsonrpc.RemoteEndpoint handleCancellation

WARNING: Unmatched cancel notification for request id 829

@mohlogan
Copy link
Contributor

mohlogan commented May 16, 2023

Experiments on: MAC: VSCode v1.78.1

Pack1: I am able to recreate the issue only with following:

  • org.eclipse.lsp4jakarta.jdt.core-0.1.1-SNAPSHOT.jar
  • org.eclipse.lsp4jakarta.ls-0.1.1-SNAPSHOT-jar-with-dependencies.jar
  • liberty-langserver-lemminx-2.0-SNAPSHOT-jar-with-dependencies.jar
  • liberty-langserver-2.0-SNAPSHOT-jar-with-dependencies.jar
  • XML v0.24.0
  • Observation:
[Error - 6:07:21 PM] Request textDocument/codeAction failed.
  Message: The request (id: 258, method: 'textDocument/codeAction') has been cancelled
  Code: -32800
  • Frequency: very soon. Multiple times

Pack2: I am NOT able to recreate with following dependency:

  • org.eclipse.lsp4jakarta.jdt.core-0.1.1-SNAPSHOT.jar
  • org.eclipse.lsp4jakarta.ls-0.1.1-SNAPSHOT-jar-with-dependencies.jar
  • liberty-langserver-1.0-M2-SNAPSHOT-jar-with-dependencies.jar
  • liberty-langserver-lemminx-1.0-M2-SNAPSHOT-jar-with-dependencies.jar
  • XML v0.24.0
  • Observation:
May 16, 2023 6:54:34 PM org.eclipse.lsp4j.jsonrpc.RemoteEndpoint handleCancellation
WARNING: Unmatched cancel notification for request id 49
  • Frequency: Very rare (only once in my testing)

@TrevCraw
Copy link
Contributor Author

For this error in the "Language Support for Jakarta EE" log....

[Error - 6:15:15 PM] Request textDocument/codeAction failed.
  Message: Request jakarta/java/codeaction failed with message: java.lang.NullPointerException: Cannot invoke "java.util.Collection.toArray()" because "<parameter1>" is null
  Code: -32603

...There is a corresponding exception in the "Language Support for Java" log. On initial glance, it looks like there are multiple issues here, but definitely looks like an NPE is occurring due to the CodeActionHandler in the org.eclipse.lsp4jakarta.jdt component.

[Error - 6:20:09 PM] May 15, 2023, 6:20:09 p.m. BadLocationException
null
org.eclipse.jface.text.BadLocationException
	at org.eclipse.jface.text.TreeLineTracker.fail(TreeLineTracker.java:1054)
	at org.eclipse.jface.text.TreeLineTracker.offsetByLine(TreeLineTracker.java:335)
	at org.eclipse.jface.text.TreeLineTracker.getLineOffset(TreeLineTracker.java:1111)
	at org.eclipse.jface.text.AbstractLineTracker.getLineOffset(AbstractLineTracker.java:252)
	at org.eclipse.jface.text.AbstractDocument.getLineOffset(AbstractDocument.java:877)
	at org.eclipse.core.internal.filebuffers.SynchronizableDocument.getLineOffset(SynchronizableDocument.java:323)
	at org.eclipse.jdt.ls.core.internal.handlers.JsonRpcHelpers.toOffset(JsonRpcHelpers.java:85)
	at org.eclipse.jdt.ls.core.internal.handlers.JsonRpcHelpers.toOffset(JsonRpcHelpers.java:69)
	at org.eclipse.jdt.ls.core.internal.corrections.DiagnosticsHelper.getEndOffset(DiagnosticsHelper.java:38)
	at org.eclipse.jdt.ls.core.internal.handlers.CodeActionHandler.getProblemLocationCores(CodeActionHandler.java:304)
	at org.eclipse.jdt.ls.core.internal.handlers.CodeActionHandler.getCodeActionCommands(CodeActionHandler.java:138)
	at org.eclipse.jdt.ls.core.internal.handlers.JDTLanguageServer.lambda$13(JDTLanguageServer.java:720)
	at org.eclipse.jdt.ls.core.internal.BaseJDTLanguageServer.lambda$0(BaseJDTLanguageServer.java:87)
	at java.base/java.util.concurrent.CompletableFuture$UniApply.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)

[Error - 10:50:10 AM] May 16, 2023, 10:50:10 a.m. Problems occurred when invoking code from plug-in: "org.eclipse.jdt.ls.core".
java.lang.NullPointerException: Cannot invoke "java.util.Collection.toArray()" because "<parameter1>" is null
java.util.concurrent.ExecutionException: java.lang.NullPointerException: Cannot invoke "java.util.Collection.toArray()" because "<parameter1>" is null
	at java.base/java.util.concurrent.CompletableFuture.reportGet(Unknown Source)
	at java.base/java.util.concurrent.CompletableFuture.get(Unknown Source)
	at org.eclipse.lsp4jakarta.jdt.internal.core.ls.JakartaDelegateCommandHandlerForJava.executeCommand(JakartaDelegateCommandHandlerForJava.java:52)
	at org.eclipse.jdt.ls.core.internal.handlers.WorkspaceExecuteCommandHandler$1.run(WorkspaceExecuteCommandHandler.java:230)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:45)
	at org.eclipse.jdt.ls.core.internal.handlers.WorkspaceExecuteCommandHandler.executeCommand(WorkspaceExecuteCommandHandler.java:220)
	at org.eclipse.jdt.ls.core.internal.handlers.JDTLanguageServer.lambda$4(JDTLanguageServer.java:585)
	at org.eclipse.jdt.ls.core.internal.BaseJDTLanguageServer.lambda$0(BaseJDTLanguageServer.java:87)
	at java.base/java.util.concurrent.CompletableFuture$UniApply.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.NullPointerException: Cannot invoke "java.util.Collection.toArray()" because "<parameter1>" is null
	at java.base/java.util.ArrayList.addAll(Unknown Source)
	at org.eclipse.lsp4jakarta.jdt.codeAction.CodeActionHandler.codeAction(CodeActionHandler.java:143)
	at org.eclipse.lsp4jakarta.jdt.core.JDTServicesManager.getCodeAction(JDTServicesManager.java:185)
	at org.eclipse.lsp4jakarta.jdt.internal.core.ls.JakartaDelegateCommandHandlerForJava.lambda$2(JakartaDelegateCommandHandlerForJava.java:143)
	at java.base/java.util.concurrent.CompletableFuture$UniApply.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.helpAsyncBlocker(Unknown Source)
	at java.base/java.util.concurrent.ForkJoinPool.helpAsyncBlocker(Unknown Source)
	at java.base/java.util.concurrent.CompletableFuture.waitingGet(Unknown Source)
	... 14 more

[Error - 10:50:10 AM] May 16, 2023, 10:50:10 a.m. Error in calling delegate command handler
java.lang.NullPointerException: Cannot invoke "java.util.Collection.toArray()" because "<parameter1>" is null
java.util.concurrent.ExecutionException: java.lang.NullPointerException: Cannot invoke "java.util.Collection.toArray()" because "<parameter1>" is null
	at java.base/java.util.concurrent.CompletableFuture.reportGet(Unknown Source)
	at java.base/java.util.concurrent.CompletableFuture.get(Unknown Source)
	at org.eclipse.lsp4jakarta.jdt.internal.core.ls.JakartaDelegateCommandHandlerForJava.executeCommand(JakartaDelegateCommandHandlerForJava.java:52)
	at org.eclipse.jdt.ls.core.internal.handlers.WorkspaceExecuteCommandHandler$1.run(WorkspaceExecuteCommandHandler.java:230)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:45)
	at org.eclipse.jdt.ls.core.internal.handlers.WorkspaceExecuteCommandHandler.executeCommand(WorkspaceExecuteCommandHandler.java:220)
	at org.eclipse.jdt.ls.core.internal.handlers.JDTLanguageServer.lambda$4(JDTLanguageServer.java:585)
	at org.eclipse.jdt.ls.core.internal.BaseJDTLanguageServer.lambda$0(BaseJDTLanguageServer.java:87)
	at java.base/java.util.concurrent.CompletableFuture$UniApply.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.NullPointerException: Cannot invoke "java.util.Collection.toArray()" because "<parameter1>" is null
	at java.base/java.util.ArrayList.addAll(Unknown Source)
	at org.eclipse.lsp4jakarta.jdt.codeAction.CodeActionHandler.codeAction(CodeActionHandler.java:143)
	at org.eclipse.lsp4jakarta.jdt.core.JDTServicesManager.getCodeAction(JDTServicesManager.java:185)
	at org.eclipse.lsp4jakarta.jdt.internal.core.ls.JakartaDelegateCommandHandlerForJava.lambda$2(JakartaDelegateCommandHandlerForJava.java:143)
	at java.base/java.util.concurrent.CompletableFuture$UniApply.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.helpAsyncBlocker(Unknown Source)
	at java.base/java.util.concurrent.ForkJoinPool.helpAsyncBlocker(Unknown Source)
	at java.base/java.util.concurrent.CompletableFuture.waitingGet(Unknown Source)
	... 14 more

@cherylking
Copy link
Member

If the reference above to XML v0.24.0 is the version of Eclipse LemMinX being used, I want to point out the following. The 2.0-SNAPSHOT of LCLS requires 0.25.0 of Eclipse LemMinX. The 1.0-M2-SNAPSHOT requires version 0.22.0 to 0.24.0. Using version 0.24.0 with both of those versions of LCLS is not valid.

@TrevCraw
Copy link
Contributor Author

Based on my experience with these errors, I do not yet see how they would be related to LemMinX or the LCLS. They seem purely related to LSP4Jakarta.

On that note, this fix in LSP4Jakarta: eclipse/lsp4jakarta#450 appears to resolve the NPE codeAction failure. Other codeAction failures are still observed.

@mohlogan
Copy link
Contributor

As part of investigation found new issue with jakarta -> eclipse/lsp4jakarta#451

@mohlogan
Copy link
Contributor

mohlogan commented May 23, 2023

After applying changes made vai eclipse/lsp4jakarta#450 i am not getting NullPointerException. But i do see codeaction failure. Investigating further.

From Vscode side i don't find much of help from developer tools. Trying to add debug with lsp4jakarta code to check further. Following 2 errors are most common:

INFO: Initializing Jakarta EE server
May 22, 2023 11:00:44 AM org.eclipse.lsp4jakarta.JakartaTextDocumentService lambda$triggerValidationFor$6
SEVERE: Return LSP4Jakarta getJavaDiagnostics() from client did not succeed
[Error - 11:00:33 AM] Request textDocument/completion failed.
  Message: The request (id: 24, method: 'textDocument/completion') has been cancelled
  Code: -32800 

But as per my observation code completion action not affected. But we do see lot of above errors. This is very common in windows. Very rare in MAC system.

@rumanaHaque
Copy link

rumanaHaque commented May 23, 2023

I was able to recreate this is my Mac.
I opened this file AnnuityWebServlet.java

After the jakarta import startements, when I try to add/delete the import statement - I got the following error.
image

I was able to try different java files in my Mac, and even if I do "Hide Output", when I hit the error, the Output window pops up.
image

@TrevCraw
Copy link
Contributor Author

@dshimo is going to investigate what options there are for suppressing these errors from LSP4Jakarta in VS Code, as they appear to be mostly benign.

@TrevCraw
Copy link
Contributor Author

Also note that while @rumanaHaque was able to reproduce the codeAction failures on her Mac machine, @dshimo was not able to reproduce it on his Mac. He also was not able to reproduce on his Linux machine - we will try another Linux machine to see the behaviour there.

Also, @scottkurz has not been able to reproduce these issues in Eclipse.

@TrevCraw
Copy link
Contributor Author

Looking at trace from Language Support for Java - the actions seem valid. Below are trace statements pulled from the logs related to request 221:

[Trace - 11:43:29 PM] Sending request 'textDocument/codeAction - (221)'.
[Trace - 11:43:29 PM] Sending notification '$/cancelRequest'.
Params: {
    "id": 221
}
[Trace - 11:43:30 PM] Received response 'textDocument/codeAction - (221)' in 24ms. Request failed: The request (id: 221, method: 'textDocument/codeAction') has been cancelled (-32800).

Need to try to understand why the request is considered "failed" when it has been cancelled. Is this something caused on the LSP4Jakarta side or is it caused by the VS Code client?

@ajm01
Copy link
Contributor

ajm01 commented May 24, 2023

I was able to recreate the codeAction failure issue on both Windows (11) and RedHat Linux (9)

@TrevCraw
Copy link
Contributor Author

Investigating changes to handleFailedRequest in the VS Code language client to see if those changes could be causing the errors to pop up.

Also tried using a try/catch similar to RedHat's VS Code extension. Did not seem to work for our scenario.

@dshimo is investigating possibly using a CancellationToken

Another possible route is to use cancelChecker on the LSP4Jakarta side.

@evie-lau

This comment was marked as duplicate.

@TrevCraw

This comment was marked as resolved.

@TrevCraw
Copy link
Contributor Author

Updating vscode-languageclient dependency to version 8.1.0 appears to resolve the main repeated codeAction failure:

[Error - 6:00:11 PM] Request textDocument/codeAction failed.
  Message: The request (id: 10, method: 'textDocument/codeAction') has been cancelled
  Code: -32800 

Other changes were made that may or may not be necessary (ie. using try/catch, using cancellationToken). Next plan of action is to test incremental changes to make sure we only use what we need.

@TrevCraw
Copy link
Contributor Author

TrevCraw commented May 29, 2023

codeAction failure from cancelled request will be resolved by #255

[Error - 6:00:11 PM] Request textDocument/codeAction failed.
  Message: The request (id: 10, method: 'textDocument/codeAction') has been cancelled
  Code: -32800 

NPE was resolved by eclipse/lsp4jakarta#450

[Error - 6:15:15 PM] Request textDocument/codeAction failed.
  Message: Request jakarta/java/codeaction failed with message: java.lang.NullPointerException: Cannot invoke "java.util.Collection.toArray()" because "<parameter1>" is null
  Code: -32603

Issue opened in LSP4Jakarta repo to address ClassCastException: eclipse/lsp4jakarta#455

[Error - 9:53:02 AM] Request textDocument/codeAction failed.

  Message: Request jakarta/java/codeaction failed with message: java.lang.ClassCastException: class org.eclipse.jdt.core.dom.TypeDeclaration cannot be cast to class org.eclipse.jdt.core.dom.MethodDeclaration (org.eclipse.jdt.core.dom.TypeDeclaration and org.eclipse.jdt.core.dom.MethodDeclaration are in unnamed module of loader org.eclipse.osgi.internal.loader.EquinoxClassLoader @25107054)

  Code: -32603

Issue opened to address unmatched cancel notification: #256

May 11, 2023 9:59:00 A.M. org.eclipse.lsp4j.jsonrpc.RemoteEndpoint handleCancellation

WARNING: Unmatched cancel notification for request id 829

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working must-fix
Projects
Status: 23.0.6
Development

Successfully merging a pull request may close this issue.

8 participants