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

Cannot cast TypeBinding$LocalTypeBinding to IVariableBinding exception on completionItem/resolve #1856

Closed
mfussenegger opened this issue Aug 25, 2021 · 7 comments · Fixed by #1858
Assignees

Comments

@mfussenegger
Copy link
Contributor

Version: latest master (05b938f)
Java 16.0.1

Got the following error when invoking completionItem/resolve with the following item:

{
  data = {
    decl_signature = "Lio.crate.expression.operator.LikeOperators$CaseSensitivity;",
    name = "SENSITIVE",
    pid = "0",
    rid = "4",
    uri = "file:///path/to/dev/crate/crate/server/src/main/java/io/crate/lucene/LuceneQueryBuilder.java"
  },
  detail = "LikeOperators.CaseSensitivity.SENSITIVE : LikeOperators.CaseSensitivity",
  insertText = "SENSITIVE",
  insertTextFormat = 2,
  kind = 20,
  label = "SENSITIVE : LikeOperators.CaseSensitivity",
  sortText = "999998698",
  textEdit = {
    newText = "SENSITIVE",
    range = {
      end = {
        character = 73,
        line = 294
      },
      start = {
        character = 71,
        line = 294
      }
    }
  }
}

The LuceneQueryBuilder is part of crate/crate on this commit

java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
	at org.eclipse.lsp4j.jsonrpc.services.GenericEndpoint.lambda$null$0(GenericEndpoint.java:67)
	at org.eclipse.lsp4j.jsonrpc.services.GenericEndpoint.request(GenericEndpoint.java:120)
	at org.eclipse.lsp4j.jsonrpc.RemoteEndpoint.handleRequest(RemoteEndpoint.java:261)
	at org.eclipse.lsp4j.jsonrpc.RemoteEndpoint.consume(RemoteEndpoint.java:190)
	at org.eclipse.jdt.ls.core.internal.ParentProcessWatcher.lambda$0(ParentProcessWatcher.java:123)
	at org.eclipse.lsp4j.jsonrpc.json.StreamMessageProducer.handleMessage(StreamMessageProducer.java:194)
	at org.eclipse.lsp4j.jsonrpc.json.StreamMessageProducer.listen(StreamMessageProducer.java:94)
	at org.eclipse.lsp4j.jsonrpc.json.ConcurrentMessageProcessor.run(ConcurrentMessageProcessor.java:113)
	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630)
	at java.base/java.lang.Thread.run(Thread.java:831)
Caused by: java.lang.reflect.InvocationTargetException
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:567)
	at org.eclipse.lsp4j.jsonrpc.services.GenericEndpoint.lambda$null$0(GenericEndpoint.java:65)
	... 12 more
Caused by: java.util.concurrent.CompletionException: java.lang.ClassCastException: class org.eclipse.jdt.core.dom.TypeBinding$LocalTypeBinding cannot be cast to class org.eclipse.jdt.core.dom.IVariableBinding (org.eclipse.jdt.core.dom.TypeBinding$LocalTypeBinding and org.eclipse.jdt.core.dom.IVariableBinding are in unnamed module of loader org.eclipse.osgi.internal.loader.EquinoxClassLoader @13acc999)
	at java.base/java.util.concurrent.CompletableFuture.encodeThrowable(CompletableFuture.java:314)
	at java.base/java.util.concurrent.CompletableFuture.completeThrowable(CompletableFuture.java:319)
	at java.base/java.util.concurrent.CompletableFuture$UniApply.tryFire(CompletableFuture.java:645)
	at java.base/java.util.concurrent.CompletableFuture$Completion.exec(CompletableFuture.java:479)
	at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:295)
	at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1016)
	at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1665)
	at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1598)
	at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:183)
Caused by: java.lang.ClassCastException: class org.eclipse.jdt.core.dom.TypeBinding$LocalTypeBinding cannot be cast to class org.eclipse.jdt.core.dom.IVariableBinding (org.eclipse.jdt.core.dom.TypeBinding$LocalTypeBinding and org.eclipse.jdt.core.dom.IVariableBinding are in unnamed module of loader org.eclipse.osgi.internal.loader.EquinoxClassLoader @13acc999)
	at org.eclipse.jdt.ls.core.internal.JDTUtils.computeFieldConstantFromTypeAST(JDTUtils.java:1330)
	at org.eclipse.jdt.ls.core.internal.JDTUtils.getConstantValue(JDTUtils.java:1221)
	at org.eclipse.jdt.ls.core.internal.handlers.CompletionResolveHandler.resolve(CompletionResolveHandler.java:198)
	at org.eclipse.jdt.ls.core.internal.handlers.JDTLanguageServer.lambda$6(JDTLanguageServer.java:544)
	at org.eclipse.jdt.ls.core.internal.BaseJDTLanguageServer.lambda$0(BaseJDTLanguageServer.java:75)
	at java.base/java.util.concurrent.CompletableFuture$UniApply.tryFire(CompletableFuture.java:642)
	... 6 more
recording.mp4
@fbricon
Copy link
Contributor

fbricon commented Aug 25, 2021

@mfussenegger can you reproduce this issue in Eclipse IDE?
Looks to me the code in JDTUtils.computeFieldConstantFromTypeAST might have been copied from upstream JDT. @snjeza added it so she should know better.

@rgrunber
Copy link
Contributor

rgrunber commented Aug 25, 2021

It comes from org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/infoviews/JavadocView.java upstream. Maybe if the code snippet for some constant (that references another constant that finally resolves to a literal) is presented in the JavadocView, it may trigger the same error.

@mfussenegger
Copy link
Contributor Author

can you reproduce this issue in Eclipse IDE?

No I didn't manage to reproduce it with Eclipse IDE - but I'm not very familiar with it (I actually haven't had it installed before)

@snjeza
Copy link
Contributor

snjeza commented Aug 25, 2021

I can't reproduce the issue in Eclipse. It is a Java LS issue.

@snjeza
Copy link
Contributor

snjeza commented Aug 25, 2021

It comes from org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/infoviews/JavadocView.java upstream

Looks to me the code in JDTUtils.computeFieldConstantFromTypeAST might have been copied from upstream JDT

You are right. I have fixed it in Java LS.

@rgrunber
Copy link
Contributor


!ENTRY org.eclipse.jface.text 2 0 2021-08-25 18:20:37.777
!MESSAGE 
!STACK 0
java.lang.ClassCastException: class org.eclipse.jdt.core.dom.TypeBinding$LocalTypeBinding cannot be cast to class org.eclipse.jdt.core.dom.IVariableBinding (org.eclipse.jdt.core.dom.TypeBinding$LocalTypeBinding and org.eclipse.jdt.core.dom.IVariableBinding are in unnamed module of loader org.eclipse.osgi.internal.loader.EquinoxClassLoader @400008bf)
	at org.eclipse.jdt.internal.ui.infoviews.JavadocView.computeFieldConstantFromTypeAST(JavadocView.java:1358)
	at org.eclipse.jdt.internal.ui.text.java.hover.JavadocHover.getConstantValue(JavadocHover.java:987)
	at org.eclipse.jdt.internal.ui.text.java.AbstractJavaCompletionProposal.addConstantOrDefaultValue(AbstractJavaCompletionProposal.java:634)
	at org.eclipse.jdt.internal.ui.text.java.AbstractJavaCompletionProposal.getAdditionalProposalInfo(AbstractJavaCompletionProposal.java:592)
	at org.eclipse.jface.text.contentassist.AdditionalInfoController$Timer$2$1.run(AdditionalInfoController.java:116)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:63)

I'm able to reproduce in Eclipse. I imported crate as a Gradle project and use the exact same steps as the video in LuceneQueryBuilder.

We can certainly fix this on our end (since we copied the code), but it's also an upstream issue.

@snjeza
Copy link
Contributor

snjeza commented Aug 25, 2021

We can certainly fix this on our end (since we copied the code), but it's also an upstream issue.

You are right. #1858 fixes it in Java LS.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants