changeset 14997:abd3693cabcc

8158169: MethodHandles.dropArgumentsToMatch(...) Reviewed-by: psandoz, mhaupt
author srastogi
date Thu, 07 Jul 2016 09:51:47 +0200
parents 45b2d1be3b08
children 22617fd44868
files src/java.base/share/classes/java/lang/invoke/MethodHandles.java test/java/lang/invoke/DropArgumentsTest.java
diffstat 2 files changed, 31 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.base/share/classes/java/lang/invoke/MethodHandles.java	Wed Jul 06 01:50:34 2016 -0700
+++ b/src/java.base/share/classes/java/lang/invoke/MethodHandles.java	Thu Jul 07 09:51:47 2016 +0200
@@ -3427,7 +3427,8 @@
      * @return a possibly adapted method handle
      * @throws NullPointerException if either argument is null
      * @throws IllegalArgumentException if any element of {@code newTypes} is {@code void.class},
-     *         or if either index is out of range in its corresponding list,
+     *         or if {@code skip} is negative or greater than the arity of the target,
+     *         or if {@code pos} is negative or greater than the newTypes list size,
      *         or if the non-skipped target parameter types match the new types at {@code pos}
      * @since 9
      */
--- a/test/java/lang/invoke/DropArgumentsTest.java	Wed Jul 06 01:50:34 2016 -0700
+++ b/test/java/lang/invoke/DropArgumentsTest.java	Thu Jul 07 09:51:47 2016 +0200
@@ -24,6 +24,7 @@
  */
 
 /* @test
+ * @bug  8158169
  * @summary unit tests for java.lang.invoke.MethodHandles
  * @run testng test.java.lang.invoke.DropArgumentsTest
  */
@@ -32,6 +33,7 @@
 import java.lang.invoke.MethodHandle;
 import java.lang.invoke.MethodHandles;
 import java.lang.invoke.MethodType;
+import java.util.Collections;
 import java.util.List;
 import static java.lang.invoke.MethodHandles.*;
 import static java.lang.invoke.MethodType.*;
@@ -78,6 +80,7 @@
             {cat, -1, bigType.parameterList(), 0},
             {cat, 0, bigType.parameterList(), -1},
             {cat, 3, bigType.parameterList(), 0},
+            {cat, 0, bigType.parameterList(), 6},
             {cat, 0, bigType.parameterList(), 2}
         };
     }
@@ -96,4 +99,30 @@
         MethodType bigTypewithVoid = cat.type().insertParameterTypes(0, void.class, String.class, int.class);
         MethodHandle handle2 = MethodHandles.dropArgumentsToMatch(cat, 0, bigTypewithVoid.parameterList(), 1);
     }
+
+    public static class MethodSet {
+
+        static void mVoid() {
+
+        }
+
+        static void mVoid(int t) {
+
+        }
+    }
+
+    @Test
+    public void dropArgumentsToMatchPosSkipRange() throws Throwable {
+        // newTypes.size() == 1, pos == 1   &&   target.paramSize() == 0, skip == 0
+        MethodHandle mh1 = MethodHandles.lookup().findStatic(MethodSet.class, "mVoid",
+                                                             MethodType.methodType(void.class));
+        MethodHandle handle1 = dropArgumentsToMatch(mh1, 0, Collections.singletonList(int.class), 1);
+        assertEquals(1, handle1.type().parameterList().size());
+
+        // newTypes.size() == 1, pos == 0   &&   target.paramSize() == 1, skip == 1
+        MethodHandle mh2 = MethodHandles.lookup().findStatic(MethodSet.class, "mVoid",
+                                                             MethodType.methodType(void.class, int.class));
+        MethodHandle handle2 = dropArgumentsToMatch(mh2, 1, Collections.singletonList(int.class), 0);
+        assertEquals(2, handle2.type().parameterList().size());
+    }
 }