-
Bug
-
Resolution: Duplicate
-
P4
-
None
-
8u221
-
x86_64
-
windows_10
ADDITIONAL SYSTEM INFORMATION :
OS: windows 10
JDK versions: 1.8.0_221, 1.8.0_131
A DESCRIPTION OF THE PROBLEM :
When using Generic type that implements two interfaces, if we use Method reference for method from the second interface java.lang.BootstrapMethodError will be thrown.
In the code example we have two classes, if use method reference for the first interface everything works.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
run main of the following class:
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
23 is printed twice.
ACTUAL -
works.printNumber(); //prints 23
fail.printNumber(); //throws: java.lang.BootstrapMethodError: call site initialization exception
---------- BEGIN SOURCE ----------
public class MethodRefBug {
interface HasInteger {
Integer getNum();
}
interface HasString {
String getText();
}
static class TextAndNumber implements HasInteger, HasString {
@Override
public Integer getNum() {
return 22;
}
@Override
public String getText() {
return "myText";
}
}
static class ThrowExceptionClass<T extends HasString & HasInteger> {
private final T t;
ThrowExceptionClass(T t) {
this.t = t;
}
void printNumber() {
Supplier<Integer> numSupplier = t::getNum;
System.out.println("numSupplier = " + numSupplier.get());
}
}
static class Working<T extends HasInteger & HasString> {
private final T t;
Working(T t) {
this.t = t;
}
void printNumber() {
Supplier<Integer> numSupplier = t::getNum;
System.out.println("numSupplier = " + numSupplier.get());
}
}
public static void main(String[] args) {
Working<TextAndNumber> works = new Working<>(new TextAndNumber());
works.printNumber(); //prints 22
ThrowExceptionClass<TextAndNumber> fail = new ThrowExceptionClass<>(new TextAndNumber());
fail.printNumber(); //throws: java.lang.BootstrapMethodError: call site initialization exception
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
use lambda expression instead of method reference
FREQUENCY : always
OS: windows 10
JDK versions: 1.8.0_221, 1.8.0_131
A DESCRIPTION OF THE PROBLEM :
When using Generic type that implements two interfaces, if we use Method reference for method from the second interface java.lang.BootstrapMethodError will be thrown.
In the code example we have two classes, if use method reference for the first interface everything works.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
run main of the following class:
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
23 is printed twice.
ACTUAL -
works.printNumber(); //prints 23
fail.printNumber(); //throws: java.lang.BootstrapMethodError: call site initialization exception
---------- BEGIN SOURCE ----------
public class MethodRefBug {
interface HasInteger {
Integer getNum();
}
interface HasString {
String getText();
}
static class TextAndNumber implements HasInteger, HasString {
@Override
public Integer getNum() {
return 22;
}
@Override
public String getText() {
return "myText";
}
}
static class ThrowExceptionClass<T extends HasString & HasInteger> {
private final T t;
ThrowExceptionClass(T t) {
this.t = t;
}
void printNumber() {
Supplier<Integer> numSupplier = t::getNum;
System.out.println("numSupplier = " + numSupplier.get());
}
}
static class Working<T extends HasInteger & HasString> {
private final T t;
Working(T t) {
this.t = t;
}
void printNumber() {
Supplier<Integer> numSupplier = t::getNum;
System.out.println("numSupplier = " + numSupplier.get());
}
}
public static void main(String[] args) {
Working<TextAndNumber> works = new Working<>(new TextAndNumber());
works.printNumber(); //prints 22
ThrowExceptionClass<TextAndNumber> fail = new ThrowExceptionClass<>(new TextAndNumber());
fail.printNumber(); //throws: java.lang.BootstrapMethodError: call site initialization exception
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
use lambda expression instead of method reference
FREQUENCY : always
- relates to
-
JDK-8142476 Call site initialization exception caused by LambdaConversionException: Invalid receiver type
-
- Closed
-