JDK-8141508 : java.lang.invoke.LambdaConversionException: Invalid receiver type ...
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 8,9
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • OS: windows_7
  • CPU: x86_64
  • Submitted: 2015-09-30
  • Updated: 2022-12-16
  • Resolved: 2015-11-11
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other JDK 8 JDK 9
,shenandoah8u332Resolved 8u321Fixed 9 b93Fixed
Related Reports
Relates :  
Relates :  
Description
FULL PRODUCT VERSION :
java version "1.8.0_60"
Java(TM) SE Runtime Environment (build 1.8.0_60-b27)
Java HotSpot(TM) 64-Bit Server VM (build 25.60-b23, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.1.7601]

A DESCRIPTION OF THE PROBLEM :
At runtime I get a java.lang.BootstrapMethodError which is caused by a java.lang.invoke.LambdaConversionException

Basically, I have a type T extends Enum<T> & Supplier<K>
and then use a method reference which refers to the Supplier's "get" method, i.e. T::get

Note: since this error occurs at run-time & involves java.lang.invoke, I filed the issue against java.lang, but it may well be that the actual issue is in the compiler.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile and execute the attached test case

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
A single line of output
ACTUAL -
An exception is thrown

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------

import java.time.LocalDate;
import java.util.EnumSet;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Function;
import java.util.function.Supplier;

public class Issue {

	public static void main(String[] args) {
		System.out.println(valueOfKey(Size.class, LocalDate.now()));
	}

	enum Size implements Supplier<LocalDate> {
		S, M, L;

		@Override
		public LocalDate get() {
			return LocalDate.now();
		}

	}

	public static <K, T extends Enum<T> & Supplier<K>> Optional<T> valueOfKey(Class<T> enumType, K key) {
		return valueOf(enumType, key, T::get);
	}

	public static <K, T extends Enum<T>> Optional<T> valueOf(Class<T> enumType, K key, Function<T, K> keyExtractor) {
		return EnumSet.allOf(enumType)
				.stream()
				.filter(t -> Objects.equals(keyExtractor.apply(t), key))
				.findFirst();
	}

}

---------- END SOURCE ----------


Comments
Fix Request (8u) A clean backport for parity with Oracle 8u331. New test passes.
12-01-2022

URL: http://hg.openjdk.java.net/jdk9/jdk9/langtools/rev/60e39427dbd0 User: lana Date: 2015-11-18 23:52:52 +0000
18-11-2015

URL: http://hg.openjdk.java.net/jdk9/dev/langtools/rev/60e39427dbd0 User: sadayapalam Date: 2015-11-11 13:16:21 +0000
11-11-2015

Interestingly, the test case in http://mail.openjdk.java.net/pipermail/compiler-dev/2015-November/009824.html calls for a completely disjoint fix vis a vis the test case in the present ticket. I'll open a fresh ticket for the test case in http://mail.openjdk.java.net/pipermail/compiler-dev/2015-November/009824.html
11-11-2015

My initial investigation also points to this being a javac defect. I'll take this one over.
06-11-2015

It's a javac bug, see http://mail.openjdk.java.net/pipermail/compiler-dev/2015-November/009824.html for an evaluation.
05-11-2015

Attached Testcase executed on JDK 8u66, 8u72 and 9EA b85, results in following exception: ----------------------------------------------------------------------------------------------- Exception in thread "main" java.lang.BootstrapMethodError: call site initialization exception at java.lang.invoke.CallSite.makeSite(CallSite.java:341) at java.lang.invoke.MethodHandleNatives.linkCallSiteImpl(MethodHandleNatives.java:307) at java.lang.invoke.MethodHandleNatives.linkCallSite(MethodHandleNatives.java:297) at TestLambdaConversion.valueOfKey(TestLambdaConversion.java:25) at TestLambdaConversion.main(TestLambdaConversion.java:11) Caused by: java.lang.invoke.LambdaConversionException: Invalid receiver type class java.lang.Enum; not a subtype of implementation type interface java.util.function.Supplier at java.lang.invoke.AbstractValidatingLambdaMetafactory.validateMetafactoryArgs(AbstractValidatingLambdaMetafactory.java:233) at java.lang.invoke.LambdaMetafactory.metafactory(LambdaMetafactory.java:303) at java.lang.invoke.CallSite.makeSite(CallSite.java:302) ... 4 more --------------------------------------------------------------------------------------------------- Moving across to dev-team for evaluation.
05-11-2015