convertArguments not handling float to double?
Charles Oliver Nutter
headius at headius.com
Mon Mar 21 01:34:03 PDT 2011
I'm running off the 20110310 build of OpenJDK from the OpenJDK OS X
build project, and had some trouble with a particular convertArguments
test.
Specifically, I tried to convert incoming args of float to outgoing
args of double, and it didn't work. It said deep in MH logic that it
wanted double but got float.
The logic, as it would be with my "invokebinder" project, is something
like this:
public static MethodHandle mixedHandle() throws Exception {
return MethodHandles.lookup().findStatic(BinderTest.class,
"mixed", MethodType.methodType(void.class, String.class, int.class,
double.class));
}
public static void mixed(String a, int b, double c) {
}
public void testConvert() throws Throwable {
MethodHandle target = mixedHandle();
MethodHandle handle = Binder
.from(String.class, Object.class, Integer.class, Float.class)
.convert(target.type())
.invoke(target);
assertEquals(MethodType.methodType(String.class, Object.class,
Integer.class, Float.class), handle.type());
// does not seem to be doing JLS conversion from float to
double; see below
assertEquals(null, handle.invokeWithArguments("foo", 5, 5.0f));
}
And the error:
1) testConvert(com.headius.invoke.binder.BinderTest)
java.lang.ClassCastException: required class java.lang.Double but
encountered class java.lang.Float
at sun.dyn.MethodHandleImpl.raiseException(MethodHandleImpl.java:1250)
at sun.dyn.FromGeneric$A3.invoke_I3(FromGeneric.java:539)
at sun.dyn.ToGeneric$A3.target(ToGeneric.java:693)
at sun.dyn.ToGeneric$A3.targetA3(ToGeneric.java:694)
at sun.dyn.ToGeneric$A3.invoke_L(ToGeneric.java:701)
at java.dyn.MethodHandle.invokeWithArguments(MethodHandle.java:427)
at com.headius.invoke.binder.BinderTest.testConvert(BinderTest.java:64)
Am I missing something? I thought float to double was fine according
to JLS, and convertArguments says it will do JLS conversions.
- Charlie
More information about the mlvm-dev
mailing list