Additional tests for constructor methodhandles
Cover case where receiver is a parent of the method handle target
type.
Bug: 138705083
Bug: 143343351
Test: art/test/run-test --host 956
Change-Id: Ic1fe34e3395748078ec08448c6c2ae7720882fe8
diff --git a/test/956-methodhandles/src/Main.java b/test/956-methodhandles/src/Main.java
index 78f6db7..a54b481 100644
--- a/test/956-methodhandles/src/Main.java
+++ b/test/956-methodhandles/src/Main.java
@@ -27,6 +27,7 @@
import java.lang.reflect.Proxy;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
+import java.util.AbstractList;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
@@ -755,6 +756,14 @@
Object[].class, MethodType.methodType(void.class));
fail("Unexpected success for array class type for findConstructor");
} catch (NoSuchMethodException e) {}
+
+ // Child class constructor (b/143343351)
+ {
+ MethodHandle handle = MethodHandles.lookup().findConstructor(
+ ArrayList.class, MethodType.methodType(void.class));
+ AbstractList list = (AbstractList) handle.asType(MethodType.methodType(AbstractList.class))
+ .invokeExact();
+ }
}
public static void testStringConstructors() throws Throwable {
@@ -874,6 +883,16 @@
fail("Unexpected string constructor result: '" + s + "'");
}
+ // Child class constructor (b/143343351)
+ {
+ MethodHandle handle = MethodHandles.lookup().findConstructor(
+ String.class, MethodType.methodType(void.class));
+ CharSequence o = (CharSequence) handle.asType(MethodType.methodType(CharSequence.class))
+ .invokeExact();
+ if (!o.equals("")) {
+ fail("Unexpected child class constructor result: '" + o + "'");
+ }
+ }
System.out.println("String constructors done.");
}