-
Bug
-
Resolution: Duplicate
-
P4
-
8
-
generic
-
generic
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
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
- duplicates
-
JDK-8142476 Call site initialization exception caused by LambdaConversionException: Invalid receiver type
- Closed