JDK-8268426 : java.lang.invoke.LambdaConversionException: Invalid receiver type class java.lang.Object; not a subtype of implementation type
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 16
  • Priority: P3
  • Status: Closed
  • Resolution: Cannot Reproduce
  • OS: windows_10
  • Submitted: 2021-06-09
  • Updated: 2021-06-18
  • Resolved: 2021-06-18
Related Reports
Relates :  
Description
Run the following code:

import java.util.List;

public class Test {

	public static void main(String[] args) {
		System.out.println("Testing with explicit type");
		MyGroup group = new MyGroup();

		System.out.println("  Testing lambda");
		if (group.getPersons().stream().anyMatch(p -> p.isFoo())) {}
		System.out.println("  Lambda is good");
		
		System.out.println("  Testing method reference");
		if (group.getPersons().stream().anyMatch(Test.Person::isFoo)) {}
		System.out.println("  Method reference is good");

		System.out.println("Testing with wildcard");
		Group<?> group2 = new MyGroup();

		System.out.println("  Testing lambda");
		if (group2.getPersons().stream().anyMatch(p -> p.isFoo())) {}
		System.out.println("  Lambda is good");
		
		System.out.println("  Testing method reference");
		if (group2.getPersons().stream().anyMatch(Test.Person::isFoo)) {}
		System.out.println("  Method reference is good");
	}

	interface Group<T extends Person> {
		List<T> getPersons();
	}

	interface Person {
		boolean isFoo();
	}

	static class MyGroup implements Group<MyPerson> {

		@Override
		public List<MyPerson> getPersons() {
			return List.of();
		}
	}

	static class MyPerson implements Person {

		@Override
		public boolean isFoo() {
			return true;
		}
	}
}

It will fail when using a method reference in combination with the parametrized type:

Testing explicit type
  Testing lambda
  Lambda is good
  Testing method reference
  Method reference is good
Testing with wildcard
  Testing lambda
  Lambda is good
  Testing method reference
Exception in thread "main" java.lang.BootstrapMethodError: bootstrap method initialization exception
	at java.base/java.lang.invoke.BootstrapMethodInvoker.invoke(BootstrapMethodInvoker.java:185)
	at java.base/java.lang.invoke.CallSite.makeSite(CallSite.java:315)
	at java.base/java.lang.invoke.MethodHandleNatives.linkCallSiteImpl(MethodHandleNatives.java:281)
	at java.base/java.lang.invoke.MethodHandleNatives.linkCallSite(MethodHandleNatives.java:271)
	at Test.main(Test.java:25)
Caused by: java.lang.invoke.LambdaConversionException: Invalid receiver type class java.lang.Object; not a subtype of implementation type interface Test$Person
	at java.base/java.lang.invoke.AbstractValidatingLambdaMetafactory.validateMetafactoryArgs(AbstractValidatingLambdaMetafactory.java:268)
	at java.base/java.lang.invoke.LambdaMetafactory.metafactory(LambdaMetafactory.java:327)
	at java.base/java.lang.invoke.BootstrapMethodInvoker.invoke(BootstrapMethodInvoker.java:127)
	... 4 more


openjdk version "16" 2021-03-16
OpenJDK Runtime Environment (build 16+36-2231)
OpenJDK 64-Bit Server VM (build 16+36-2231, mixed mode, sharing)
Comments
OK, closed.
18-06-2021

Then it seems to be a local issue somehow. I'm fine with closing as Cannot Reproduce, and if I find anything new on this I will reopen.
17-06-2021

Hi Nir, I used the `jdk16 build 16+36` to run the demo. It works well. It seems that the issue can't be reproduced at linux. Maybe you can use jdk16u or jdk17 to run it at windows. Then you can sure whether it is an issue at windows. And we need someone test it at Mac, too.
16-06-2021

Can you test using the same JDK build I used? Could it have been fixed in the meantime?
16-06-2021

The jdk17 (https://github.com/openjdk/jdk17) and main line (https://github.com/openjdk/jdk) also work well at Linux. I had not tested it at windows or Mac.
16-06-2021

I used the jdk16u (https://github.com/openjdk/jdk16u) to compile this demo and run it. It completed successfully without the exception message. My local environment is x86_64&linux instead of windows.
16-06-2021