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

ClassCastException in qute template #816

Closed
fbricon opened this issue Mar 15, 2023 · 2 comments · Fixed by #817
Closed

ClassCastException in qute template #816

fbricon opened this issue Mar 15, 2023 · 2 comments · Fixed by #817
Assignees
Labels
bug Something isn't working code action qute
Milestone

Comments

@fbricon
Copy link
Collaborator

fbricon commented Mar 15, 2023

In a qute template, the following will trigger a ClassCastException:

    {#if !}

    {/if}

See:

[Trace - 18:50:59] Sending request 'textDocument/codeAction - (2217)'.
Mar 15, 2023 6:50:59 PM org.eclipse.lsp4j.jsonrpc.RemoteEndpoint fallbackResponseError
SEVERE: Internal error: java.lang.ClassCastException: class com.redhat.qute.parser.expression.Parts cannot be cast to class com.redhat.qute.parser.expression.ObjectPart (com.redhat.qute.parser.expression.Parts and com.redhat.qute.parser.expression.ObjectPart are in unnamed module of loader 'app')
java.util.concurrent.CompletionException: java.lang.ClassCastException: class com.redhat.qute.parser.expression.Parts cannot be cast to class com.redhat.qute.parser.expression.ObjectPart (com.redhat.qute.parser.expression.Parts and com.redhat.qute.parser.expression.ObjectPart are in unnamed module of loader 'app')
	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$UniCompose.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.ClassCastException: class com.redhat.qute.parser.expression.Parts cannot be cast to class com.redhat.qute.parser.expression.ObjectPart (com.redhat.qute.parser.expression.Parts and com.redhat.qute.parser.expression.ObjectPart are in unnamed module of loader 'app')
	at com.redhat.qute.services.codeactions.QuteCodeActionForUndefinedObject.doCodeActions(QuteCodeActionForUndefinedObject.java:77)
	at com.redhat.qute.services.QuteCodeActions.doCodeActions(QuteCodeActions.java:116)
	at com.redhat.qute.services.QuteLanguageService.doCodeActions(QuteLanguageService.java:104)
	at com.redhat.qute.ls.template.TemplateFileTextDocumentService.lambda$codeAction$9(TemplateFileTextDocumentService.java:165)
	at com.redhat.qute.ls.commons.ModelTextDocuments.lambda$computeModelAsyncCompose$1(ModelTextDocuments.java:144)
	... 7 more

[Trace - 18:50:59] Received response 'textDocument/codeAction - (2217)' in 1ms. Request failed: Internal error. (-32603).
[Error - 18:50:59] Request textDocument/codeAction failed.
  Message: Internal error.
  Code: -32603 
java.util.concurrent.CompletionException: java.lang.ClassCastException: class com.redhat.qute.parser.expression.Parts cannot be cast to class com.redhat.qute.parser.expression.ObjectPart (com.redhat.qute.parser.expression.Parts and com.redhat.qute.parser.expression.ObjectPart are in unnamed module of loader 'app')
	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$UniCompose.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.ClassCastException: class com.redhat.qute.parser.expression.Parts cannot be cast to class com.redhat.qute.parser.expression.ObjectPart (com.redhat.qute.parser.expression.Parts and com.redhat.qute.parser.expression.ObjectPart are in unnamed module of loader 'app')
	at com.redhat.qute.services.codeactions.QuteCodeActionForUndefinedObject.doCodeActions(QuteCodeActionForUndefinedObject.java:77)
	at com.redhat.qute.services.QuteCodeActions.doCodeActions(QuteCodeActions.java:116)
	at com.redhat.qute.services.QuteLanguageService.doCodeActions(QuteLanguageService.java:104)
	at com.redhat.qute.ls.template.TemplateFileTextDocumentService.lambda$codeAction$9(TemplateFileTextDocumentService.java:165)
	at com.redhat.qute.ls.commons.ModelTextDocuments.lambda$computeModelAsyncCompose$1(ModelTextDocuments.java:144)
	... 7 more

[Trace - 18:50:59] Sending notification 'textDocument/didSave'.
[Trace - 18:51:00] Sending notification 'workspace/didChangeWatchedFiles'.
[Trace - 18:51:00] Received notification 'textDocument/publishDiagnostics'.
[Trace - 18:51:00] Sending request 'textDocument/codeAction - (2218)'.
Mar 15, 2023 6:51:00 PM org.eclipse.lsp4j.jsonrpc.RemoteEndpoint fallbackResponseError
SEVERE: Internal error: java.lang.ClassCastException: class com.redhat.qute.parser.expression.Parts cannot be cast to class com.redhat.qute.parser.expression.ObjectPart (com.redhat.qute.parser.expression.Parts and com.redhat.qute.parser.expression.ObjectPart are in unnamed module of loader 'app')
java.util.concurrent.CompletionException: java.lang.ClassCastException: class com.redhat.qute.parser.expression.Parts cannot be cast to class com.redhat.qute.parser.expression.ObjectPart (com.redhat.qute.parser.expression.Parts and com.redhat.qute.parser.expression.ObjectPart are in unnamed module of loader 'app')
	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$UniCompose.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.ClassCastException: class com.redhat.qute.parser.expression.Parts cannot be cast to class com.redhat.qute.parser.expression.ObjectPart (com.redhat.qute.parser.expression.Parts and com.redhat.qute.parser.expression.ObjectPart are in unnamed module of loader 'app')
	at com.redhat.qute.services.codeactions.QuteCodeActionForUndefinedObject.doCodeActions(QuteCodeActionForUndefinedObject.java:77)
	at com.redhat.qute.services.QuteCodeActions.doCodeActions(QuteCodeActions.java:116)
	at com.redhat.qute.services.QuteLanguageService.doCodeActions(QuteLanguageService.java:104)
	at com.redhat.qute.ls.template.TemplateFileTextDocumentService.lambda$codeAction$9(TemplateFileTextDocumentService.java:165)
	at com.redhat.qute.ls.commons.ModelTextDocuments.lambda$computeModelAsyncCompose$1(ModelTextDocuments.java:144)
	... 7 more

[Trace - 18:51:00] Received response 'textDocument/codeAction - (2218)' in 2ms. Request failed: Internal error. (-32603).
[Error - 18:51:00] Request textDocument/codeAction failed.
  Message: Internal error.
  Code: -32603 
java.util.concurrent.CompletionException: java.lang.ClassCastException: class com.redhat.qute.parser.expression.Parts cannot be cast to class com.redhat.qute.parser.expression.ObjectPart (com.redhat.qute.parser.expression.Parts and com.redhat.qute.parser.expression.ObjectPart are in unnamed module of loader 'app')
	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$UniCompose.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.ClassCastException: class com.redhat.qute.parser.expression.Parts cannot be cast to class com.redhat.qute.parser.expression.ObjectPart (com.redhat.qute.parser.expression.Parts and com.redhat.qute.parser.expression.ObjectPart are in unnamed module of loader 'app')
	at com.redhat.qute.services.codeactions.QuteCodeActionForUndefinedObject.doCodeActions(QuteCodeActionForUndefinedObject.java:77)
	at com.redhat.qute.services.QuteCodeActions.doCodeActions(QuteCodeActions.java:116)
	at com.redhat.qute.services.QuteLanguageService.doCodeActions(QuteLanguageService.java:104)
	at com.redhat.qute.ls.template.TemplateFileTextDocumentService.lambda$codeAction$9(TemplateFileTextDocumentService.java:165)
	at com.redhat.qute.ls.commons.ModelTextDocuments.lambda$computeModelAsyncCompose$1(ModelTextDocuments.java:144)
	... 7 more

Tested with the latest vscode-quarkus pre-release (v1.13.2023031404)

@fbricon fbricon added bug Something isn't working qute labels Mar 15, 2023
@rgrunber
Copy link
Member

@datho7561 , could we solve this by adding something like
literalJavaType != null || object.getPartName().isEmpty() at

String literalJavaType = LiteralSupport.getLiteralJavaType(objectPart.getPartName());
if (literalJavaType != null) {
// The object part is a literal type (ex : true)
return null;
}
?

It doesn't make sense to emit UndefinedObject when we can't define it because it isn't a valid identifier.

@angelozerr angelozerr self-assigned this Mar 16, 2023
@angelozerr angelozerr added this to the 0.14.0 milestone Mar 16, 2023
angelozerr added a commit to angelozerr/quarkus-ls that referenced this issue Mar 16, 2023
angelozerr added a commit to angelozerr/quarkus-ls that referenced this issue Mar 16, 2023
@angelozerr
Copy link
Contributor

It doesn't make sense to emit UndefinedObject when we can't define it because it isn't a valid identifier.

@rgrunber indeed it was the idea, but ! can be used as object part if it is not an #if section.

Here the result:

image

Here we don't report error as UndefinedObject. Please note that the error should highlight the ! and note the {, but this error comes from the real Qute parser which is not fault tolerant, so it means if you write:

{#if !}

    {/if}
{#if !}

    {/if}

you will have just one error of the first { and teh offset is not correct.

To fix those 2 problems we should manage this error with our QuteDiagnostics which uses our fault tolerant parser. I had started to manage an error to adjust correctly the error (I ignore the error from the Qute real parser and I manage itin QuteDiagnostics), but I'm waiting for the decision about the Qute parser (managed with Antlr?)

//cc @mkouba @JessicaJHee @datho7561

angelozerr added a commit to angelozerr/quarkus-ls that referenced this issue Mar 16, 2023
datho7561 pushed a commit that referenced this issue Mar 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working code action qute
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants