Bug 547203 - ClassCastException during Java Search: TypeVariableBinding cannot be cast to SourceTypeBinding
Summary: ClassCastException during Java Search: TypeVariableBinding cannot be cast to ...
Status: NEW
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.12   Edit
Hardware: PC Mac OS X
: P3 normal with 1 vote (vote)
Target Milestone: ---   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords: needinfo
Depends on:
Blocks:
 
Reported: 2019-05-12 15:46 EDT by Gunnar Wagenknecht CLA
Modified: 2023-06-13 12:04 EDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Gunnar Wagenknecht CLA 2019-05-12 15:46:52 EDT
org.eclipse.core.jobs
Error
Sun May 12 12:41:56 PDT 2019
An internal error occurred during: "Java Search".

java.lang.ClassCastException: class org.eclipse.jdt.internal.compiler.lookup.TypeVariableBinding cannot be cast to class org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding (org.eclipse.jdt.internal.compiler.lookup.TypeVariableBinding and org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding are in unnamed module of loader org.eclipse.osgi.internal.loader.EquinoxClassLoader @5f9f1886)
	at org.eclipse.jdt.internal.compiler.lookup.ClassScope.detectHierarchyCycle(ClassScope.java:1322)
	at org.eclipse.jdt.internal.compiler.lookup.ClassScope.detectHierarchyCycle(ClassScope.java:1279)
	at org.eclipse.jdt.internal.compiler.lookup.ClassScope.detectHierarchyCycle(ClassScope.java:1205)
	at org.eclipse.jdt.internal.compiler.ast.SingleTypeReference.getTypeBinding(SingleTypeReference.java:73)
	at org.eclipse.jdt.internal.compiler.ast.TypeReference.internalResolveType(TypeReference.java:514)
	at org.eclipse.jdt.internal.compiler.ast.TypeReference.resolveType(TypeReference.java:624)
	at org.eclipse.jdt.internal.compiler.ast.TypeReference.resolveType(TypeReference.java:620)
	at org.eclipse.jdt.internal.compiler.ast.TypeReference.resolveSuperType(TypeReference.java:592)
	at org.eclipse.jdt.internal.compiler.lookup.ClassScope.findSupertype(ClassScope.java:1337)
	at org.eclipse.jdt.internal.compiler.lookup.ClassScope.connectSuperclass(ClassScope.java:962)
	at org.eclipse.jdt.internal.compiler.lookup.ClassScope.connectTypeHierarchy(ClassScope.java:1123)
	at org.eclipse.jdt.internal.compiler.lookup.ClassScope.connectMemberTypes(ClassScope.java:930)
	at org.eclipse.jdt.internal.compiler.lookup.ClassScope.connectTypeHierarchy(ClassScope.java:1132)
	at org.eclipse.jdt.internal.compiler.lookup.CompilationUnitScope.connectTypeHierarchy(CompilationUnitScope.java:361)
	at org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment.completeTypeBindings(LookupEnvironment.java:507)
	at org.eclipse.jdt.internal.core.search.matching.MatchLocator.locateMatches(MatchLocator.java:1311)
	at org.eclipse.jdt.internal.core.search.matching.MatchLocator.locateMatches(MatchLocator.java:1377)
	at org.eclipse.jdt.internal.core.search.matching.MatchLocator.locateMatches(MatchLocator.java:1496)
	at org.eclipse.jdt.internal.core.search.JavaSearchParticipant.locateMatches(JavaSearchParticipant.java:112)
	at org.eclipse.jdt.internal.core.search.BasicSearchEngine.findMatches(BasicSearchEngine.java:250)
	at org.eclipse.jdt.internal.core.search.BasicSearchEngine.search(BasicSearchEngine.java:595)
	at org.eclipse.jdt.core.search.SearchEngine.search(SearchEngine.java:670)
	at org.eclipse.jdt.internal.ui.search.JavaSearchQuery.run(JavaSearchQuery.java:178)
	at org.eclipse.search2.internal.ui.InternalSearchUI$InternalSearchJob.run(InternalSearchUI.java:95)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:63)
Comment 1 Andrey Loskutov CLA 2019-05-12 16:39:19 EDT
Can you please provide steps to reproduce?
Comment 2 Gunnar Wagenknecht CLA 2019-05-12 17:10:23 EDT
- Placed cursor on method name
- Invoked Cmd+Shift+G (Search for references)

The project is closed source. Thus, I cannot copy/paste the code here. The method was in a class without any special hierarchy, i.e. didn't extend any other class or implemented an interface.
Comment 3 Andrey Loskutov CLA 2019-05-12 17:14:14 EDT
What was the project JDK version configured and what was the runtime JDK? 9+?
Comment 4 Gunnar Wagenknecht CLA 2019-05-12 18:09:59 EDT
Java 11 in both cases
Comment 5 Stephan Herrmann CLA 2019-05-16 11:07:18 EDT
C'mon Gunnar, you know we need more information :)

Eg.: which Eclipse build?

Any chance that somewhere in your project you have code vaguely similar to this?
//--
class C<T> {
   class B implements T {
   }
}
//--

any compile errors?
Comment 6 Gunnar Wagenknecht CLA 2019-05-16 11:31:55 EDT
(In reply to Stephan Herrmann from comment #5)
> Eg.: which Eclipse build?

4.12 as selected in Bugzille. 2019-03 official release. If it's a special build I'd have probably not reported it. :)


> Any chance that somewhere in your project you have code vaguely similar to
> this?
> //--
> class C<T> {
>    class B implements T {
>    }
> }
> //--

Well, not exactly sure but yes, lots of Generics when I ran into this.
 
> any compile errors?

Likely. This is a large code base I was looking into. Thus, that's why is hard to extract a reproducible test.

It's a CCE. Probably something unexpected was returned. I suggest enhancing code like this with additional log/exception output for your analysis. This might help reporting these issues easier instead of throwing CCE to users.
Comment 7 Stephan Herrmann CLA 2019-05-17 09:44:05 EDT
(In reply to Gunnar Wagenknecht from comment #6)
> (In reply to Stephan Herrmann from comment #5)
> > Any chance that somewhere in your project you have code vaguely similar to
> > this?
> > //--
> > class C<T> {
> >    class B implements T {
> >    }
> > }
> > //--
> 
> Well, not exactly sure but yes, lots of Generics when I ran into this.

To be specific: the stack trace seems to imply that some type tried to declare a supertype using a type variable. This is plain wrong and you may expect all kinds of breakage if you try to further analyse / search such code.

Note, that the compiler has no place that it can possibly log to.
Comment 8 Robert Ross CLA 2019-06-26 09:30:34 EDT
I am also seeing this with latest Eclipse and Java 11 project.
Comment 9 Stephan Herrmann CLA 2019-06-26 10:50:56 EDT
(In reply to Robert Ross from comment #8)
> I am also seeing this with latest Eclipse and Java 11 project.

So we have one more candidate who could possibly provide a reproducing example. I'm all ears.
Comment 10 Robert Ross CLA 2019-06-26 10:57:49 EDT
The best I can provide right now is a stack trace.  Creating a "reproducing example" would require someone to know what is causing the issue to begin with.  Eclipse is a complicated collection of plugins, so I couldn't even be sure that your baseline test environment is the same as mine without essentially figuring out the root cause.  I simply don't have the time to do that.  However, I can confirm that this isn't an isolated incident.

When this occurs, it appears to corrupt the search index so that subsequent calls to search for Java references return 0 results all the time.  In order to even get the error again, I need to close out Eclipse, wipe out everything in .metadata\.plugins\org.eclipse.jdt.core and then restart Eclipse.  I can then do a search for references again and get the exact same error stack reported by Gunnar.
Comment 11 Eclipse Genie CLA 2021-06-16 20:25:54 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.
Comment 12 Eclipse Genie CLA 2023-06-13 12:04:13 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.