changeset 13124:ff8ce38663d9

8143798: jck failures: api/java_lang/invoke/MethodHandle/index_MethodsTests[asSpreaderWMTE]: java.lang.VerifyError: Bad type on operand stack Reviewed-by: vlivanov
author mhaupt
date Wed, 25 Nov 2015 09:23:07 +0100
parents fc3266c221b7
children 6abacd981c4a
files src/java.base/share/classes/java/lang/invoke/MethodHandle.java test/java/lang/invoke/T8139885.java
diffstat 2 files changed, 14 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.base/share/classes/java/lang/invoke/MethodHandle.java	Wed Nov 25 13:29:14 2015 +0900
+++ b/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/test/java/lang/invoke/T8139885.java	Wed Nov 25 13:29:14 2015 +0900
+++ b/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());