JDK-8308360 : LambdaConversionException when using ::-Operator and Generics
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.lang.invoke
  • Affected Version: 8
  • Priority: P4
  • Status: Resolved
  • Resolution: Duplicate
  • OS: generic
  • CPU: generic
  • Submitted: 2023-05-17
  • Updated: 2023-07-24
  • Resolved: 2023-07-19
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
tbdResolved
Related Reports
Duplicate :  
Description
A DESCRIPTION OF THE PROBLEM :
Calling a method via the ::-Operator on a parameter of a generic Type that implements an Interface and extends an abstract class throws a LambdaConversionException if the method is from the interface.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the minimal example provided as source code using java 8

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
No crash
ACTUAL -
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 Main.bar(Main.java:11)
	at Main.main(Main.java:20)
Caused by: java.lang.invoke.LambdaConversionException: Invalid receiver type class Main$I; not a subtype of implementation type interface Main$J
	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

---------- BEGIN SOURCE ----------
public class Main {

  abstract static class I {
  }

  interface J {
    void foo();
  }

  static <T extends I & J> void bar(T t) {
    Runnable r = t::foo; //crashes
//    Runnable r = () -> t.foo(); //works fine
  }

  public static void main(String[] args) {
    class A extends I implements J {
      public void foo() {
      }
    }
    bar(new A());
  }
}
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Works in newer Java Versions than 8

FREQUENCY : always



Comments
Duplicate of JDK-8142476 which was fixed in JDK 9.
19-07-2023

The observations on Windows 10: JDK 8: Failed, Exception observed. JDK 11: Passed. JDK 17: Passed.
18-05-2023