MethodHandle.bindTo chain fails with "IllegalArgumentException: no leading reference parameter"

Tobias Hartmann tobias.hartmann at
Tue Jul 25 15:26:26 UTC 2017


below test fails with:
Exception in thread "main" java.lang.IllegalArgumentException: no leading reference parameter
	at java.base/java.lang.invoke.MethodHandleStatics.newIllegalArgumentException(
	at java.base/java.lang.invoke.MethodType.leadingReferenceParameter(
	at java.base/java.lang.invoke.MethodHandle.bindTo(
	at Test.test(
	at Test.main(

Am I doing something wrong or is this case not yet supported?


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) {
      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();

More information about the valhalla-dev mailing list