When invokedynamic instruction or MethodHandles.convertArguments() needs to convert between primary types, an exception like the one below is thrown:
Exception in thread "main" java.lang.ClassCastException: java.lang.Boolean cannot be cast to java.lang.Byte
at sun.dyn.util.ValueConversions.unboxByte(ValueConversions.java:61)
at sun.dyn.util.ValueConversions.unboxByteRaw(ValueConversions.java:98)
at sun.dyn.ToGeneric$Adapter.return_I(ToGeneric.java:393)
at sun.dyn.ToGeneric$A1.invoke_I(ToGeneric.java:643)
A short test case for this:
import java.dyn.*;
public class R {
public static void main(String... args) throws Throwable {
MethodHandle mh1 = MethodHandles.identity(int.class);
MethodHandle mh2 = MethodHandles.convertArguments(mh1, MethodType.methodType(short.class, int.class));
short s = (short) mh2.invokeExact(123);
}
}
Exception in thread "main" java.lang.ClassCastException: java.lang.Boolean cannot be cast to java.lang.Byte
at sun.dyn.util.ValueConversions.unboxByte(ValueConversions.java:61)
at sun.dyn.util.ValueConversions.unboxByteRaw(ValueConversions.java:98)
at sun.dyn.ToGeneric$Adapter.return_I(ToGeneric.java:393)
at sun.dyn.ToGeneric$A1.invoke_I(ToGeneric.java:643)
A short test case for this:
import java.dyn.*;
public class R {
public static void main(String... args) throws Throwable {
MethodHandle mh1 = MethodHandles.identity(int.class);
MethodHandle mh2 = MethodHandles.convertArguments(mh1, MethodType.methodType(short.class, int.class));
short s = (short) mh2.invokeExact(123);
}
}
- duplicates
-
JDK-6939861 JVM should handle more conversion operations
- Closed
- relates to
-
JDK-6998541 JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
- Closed