MethodHandle.bindTo chain fails with "IllegalArgumentException: no leading reference parameter"
Tobias Hartmann
tobias.hartmann at oracle.com
Tue Jul 25 15:26:26 UTC 2017
Hi,
below test fails with:
Exception in thread "main" java.lang.IllegalArgumentException: no leading reference parameter
at java.base/java.lang.invoke.MethodHandleStatics.newIllegalArgumentException(MethodHandleStatics.java:134)
at java.base/java.lang.invoke.MethodType.leadingReferenceParameter(MethodType.java:531)
at java.base/java.lang.invoke.MethodHandle.bindTo(MethodHandle.java:1419)
at Test.test(Test.java:35)
at Test.main(Test.java:41)
Am I doing something wrong or is this case not yet supported?
Thanks,
Tobias
import java.lang.invoke.*;
__ByValue final class MyValue1 {
final int x;
private MyValue1() {
this.x = 0;
}
__ValueFactory static MyValue1 createDefaultInline() {
return __MakeDefault MyValue1();
}
}
public class Test {
static final MethodHandle mh;
static {
try {
mh = MethodHandles.lookup().unreflect(Test.class.getMethod("test_target", MyValue1.class));
} catch (NoSuchMethodException|IllegalAccessException e) {
e.printStackTrace();
throw new RuntimeException("method handle lookup fails");
}
}
MyValue1 test_vt = MyValue1.createDefaultInline();
public int test_target(MyValue1 vt) {
return vt.x;
}
long test() throws Throwable {
MethodHandle mh1 = mh.bindTo(this);
MethodHandle mh2 = mh1.bindTo(test_vt);
return (long)mh2.invoke();
}
public static void main(String[] args) throws Throwable {
Test t = new Test();
t.test();
}
}
More information about the valhalla-dev
mailing list