--- a/jdk/src/java.base/share/classes/java/lang/invoke/MethodHandles.java Wed Jul 06 01:50:34 2016 -0700
+++ b/jdk/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/jdk/test/java/lang/invoke/DropArgumentsTest.java Wed Jul 06 01:50:34 2016 -0700
+++ b/jdk/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());
+ }
}