8143798: jck failures: api/java_lang/invoke/MethodHandle/index_MethodsTests[asSpreaderWMTE]: java.lang.VerifyError: Bad type on operand stack
authormhaupt
Wed, 25 Nov 2015 09:23:07 +0100
changeset 34336 3f251ae0f2d3
parent 34335 ef0ba9ee7cde
child 34337 b088bf935e4b
8143798: jck failures: api/java_lang/invoke/MethodHandle/index_MethodsTests[asSpreaderWMTE]: java.lang.VerifyError: Bad type on operand stack Reviewed-by: vlivanov
jdk/src/java.base/share/classes/java/lang/invoke/MethodHandle.java
jdk/test/java/lang/invoke/T8139885.java
--- a/jdk/src/java.base/share/classes/java/lang/invoke/MethodHandle.java	Wed Nov 25 13:29:14 2015 +0900
+++ b/jdk/src/java.base/share/classes/java/lang/invoke/MethodHandle.java	Wed Nov 25 09:23:07 2015 +0100
@@ -938,7 +938,7 @@
         Class<?> arrayElement = arrayType.getComponentType();
         MethodType mtype = type();
         boolean match = true, fail = false;
-        for (int i = pos; i < arrayLength; i++) {
+        for (int i = pos; i < pos + arrayLength; i++) {
             Class<?> ptype = mtype.parameterType(i);
             if (ptype != arrayElement) {
                 match = false;
--- a/jdk/test/java/lang/invoke/T8139885.java	Wed Nov 25 13:29:14 2015 +0900
+++ b/jdk/test/java/lang/invoke/T8139885.java	Wed Nov 25 09:23:07 2015 +0100
@@ -34,6 +34,7 @@
 import java.lang.invoke.MethodHandles;
 import java.lang.invoke.MethodHandles.Lookup;
 import java.lang.invoke.MethodType;
+import java.lang.invoke.WrongMethodTypeException;
 import java.util.*;
 
 import static java.lang.invoke.MethodType.methodType;
@@ -413,6 +414,18 @@
     }
 
     @Test
+    public static void testAsSpreaderIllegalMethodType() throws Throwable {
+        MethodHandle h = MethodHandles.dropArguments(MethodHandles.constant(String.class, ""), 0, int.class, int.class);
+        boolean caught = false;
+        try {
+            MethodHandle s = h.asSpreader(String[].class, 1);
+        } catch (WrongMethodTypeException wmte) {
+            caught = true;
+        }
+        assertTrue(caught);
+    }
+
+    @Test
     public static void testAsCollector() throws Throwable {
         MethodHandle collector = SpreadCollect.MH_forCollecting.asCollector(1, int[].class, 1);
         assertEquals(SpreadCollect.MT_collector1, collector.type());