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

Incomplete type hierarchy when using method reference #830

Open
trancexpress opened this issue Mar 13, 2023 · 2 comments · May be fixed by #832
Open

Incomplete type hierarchy when using method reference #830

trancexpress opened this issue Mar 13, 2023 · 2 comments · May be fixed by #832
Labels
bug Something isn't working

Comments

@trancexpress
Copy link
Contributor

See: https://bugs.eclipse.org/bugs/show_bug.cgi?id=560545

To reproduce, compute the type hierarchy of TestInterface in the following snippet:

public class TestClass {

	interface TestInterface {
		void testMethod();
	}

	public TestInterface ti1 = TestClass.this::testMethod;
	public TestInterface ti2 = () -> testMethod();
	public TestInterface ti3 = new TestInterface() {
		public void testMethod() {
			TestClass.this.testMethod();
		}
	};

	public void testMethod() {
		System.out.println("TestClass.testMethod()");
	}

	public static void main(String[] args) {
		TestClass t = new TestClass();
		t.ti1.testMethod();
		t.ti2.testMethod();
		t.ti3.testMethod();
	}
}

Observe that no implementer is found for the method reference. Only for the lambda and the anonymous type.

@trancexpress
Copy link
Contributor Author

trancexpress commented Mar 13, 2023

Example stack trace when a subtype is found (the lambda):

"Worker-5: Computing type hierarchy of 'TestInterface - test.TestClass'..." #122 prio=5 os_prio=0 cpu=676.35ms elapsed=1091.81s tid=0x00007f0e3c001670 nid=0xe759 at breakpoint [0x00007f0ef1798000]
   java.lang.Thread.State: RUNNABLE
        at org.eclipse.jdt.internal.core.hierarchy.TypeHierarchy.addSubtype(TypeHierarchy.java:238)
        at org.eclipse.jdt.internal.core.hierarchy.TypeHierarchy.cacheSuperInterfaces(TypeHierarchy.java:297)
        at org.eclipse.jdt.internal.core.hierarchy.HierarchyBuilder.connect(HierarchyBuilder.java:193)
        at org.eclipse.jdt.internal.core.hierarchy.HierarchyResolver.reportHierarchy(HierarchyResolver.java:613)
        at org.eclipse.jdt.internal.core.hierarchy.HierarchyResolver.resolve(HierarchyResolver.java:900)
        at org.eclipse.jdt.internal.core.hierarchy.IndexBasedHierarchyBuilder.buildForProject(IndexBasedHierarchyBuilder.java:265)
        at org.eclipse.jdt.internal.core.hierarchy.IndexBasedHierarchyBuilder.buildFromPotentialSubtypes(IndexBasedHierarchyBuilder.java:376)
        at org.eclipse.jdt.internal.core.hierarchy.IndexBasedHierarchyBuilder.build(IndexBasedHierarchyBuilder.java:166)
        at org.eclipse.jdt.internal.core.hierarchy.TypeHierarchy.compute(TypeHierarchy.java:323)
        at org.eclipse.jdt.internal.core.hierarchy.TypeHierarchy.refresh(TypeHierarchy.java:1319)
        - locked <0x0000000615f71400> (a org.eclipse.jdt.internal.core.hierarchy.TypeHierarchy)
        at org.eclipse.jdt.internal.ui.typehierarchy.TypeHierarchyLifeCycle.doHierarchyRefresh(TypeHierarchyLifeCycle.java:331)
        at org.eclipse.jdt.internal.ui.typehierarchy.TypeHierarchyLifeCycle.doHierarchyRefreshBackground(TypeHierarchyLifeCycle.java:272)
        at org.eclipse.jdt.internal.ui.typehierarchy.TypeHierarchyLifeCycle$1.run(TypeHierarchyLifeCycle.java:225)
        at org.eclipse.core.internal.jobs.Worker.run(Worker.java:63)

HierarchyResolver.typeBindings is being iterated over in HierarchyResolver.reportHierarchy(), it doesn't contain anything about the method reference.

The lambda is stored here:

"Worker-14: Computing type hierarchy of 'TestInterface - test.TestClass'..." #333 prio=5 os_prio=0 cpu=191.82ms elapsed=1131.52s tid=0x00007f50e4001670 nid=0xb4ab at breakpoint [0x00007f51c85fe000]
   java.lang.Thread.State: RUNNABLE
        at org.eclipse.jdt.internal.core.hierarchy.HierarchyResolver.remember(HierarchyResolver.java:435)
        at org.eclipse.jdt.internal.core.hierarchy.HierarchyResolver.remember(HierarchyResolver.java:442)
        at org.eclipse.jdt.internal.core.hierarchy.HierarchyResolver.rememberAllTypes(HierarchyResolver.java:535)
        at org.eclipse.jdt.internal.core.hierarchy.HierarchyResolver.resolve(HierarchyResolver.java:874)
        at org.eclipse.jdt.internal.core.hierarchy.IndexBasedHierarchyBuilder.buildForProject(IndexBasedHierarchyBuilder.java:265)
        at org.eclipse.jdt.internal.core.hierarchy.IndexBasedHierarchyBuilder.buildFromPotentialSubtypes(IndexBasedHierarchyBuilder.java:376)
        at org.eclipse.jdt.internal.core.hierarchy.IndexBasedHierarchyBuilder.build(IndexBasedHierarchyBuilder.java:166)
        at org.eclipse.jdt.internal.core.hierarchy.TypeHierarchy.compute(TypeHierarchy.java:323)
        at org.eclipse.jdt.internal.core.hierarchy.TypeHierarchy.refresh(TypeHierarchy.java:1319)
        - locked <0x000000062bc21430> (a org.eclipse.jdt.internal.core.hierarchy.TypeHierarchy)
        at org.eclipse.jdt.internal.ui.typehierarchy.TypeHierarchyLifeCycle.doHierarchyRefresh(TypeHierarchyLifeCycle.java:331)
        at org.eclipse.jdt.internal.ui.typehierarchy.TypeHierarchyLifeCycle.doHierarchyRefreshBackground(TypeHierarchyLifeCycle.java:272)
        at org.eclipse.jdt.internal.ui.typehierarchy.TypeHierarchyLifeCycle$1.run(TypeHierarchyLifeCycle.java:225)
        at org.eclipse.core.internal.jobs.Worker.run(Worker.java:63)

Maybe extra code is needed around the fix for https://bugs.eclipse.org/bugs/show_bug.cgi?id=400905, in HierarchyResolver.rememberAllTypes()... And in particular something like this will have to be added for method references that are assigned to a local variable (or a field): org.eclipse.jdt.internal.compiler.ast.LambdaExpression.getTypeBinding().LambdaTypeBinding

There is a bunch of other code around this LambdaTypeBinding, see e.g. HandleFactory.createLambdaTypeElement()

trancexpress added a commit to trancexpress/eclipse.jdt.core that referenced this issue Mar 13, 2023
@trancexpress
Copy link
Contributor Author

Would be good if we also take care of or make progress towards this bug: https://bugs.eclipse.org/bugs/show_bug.cgi?id=539602

@trancexpress trancexpress added the bug Something isn't working label Mar 16, 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
Projects
None yet
1 participant