changeset 14686:5be0d816aff5

8158171: MethodHandles.dropArgumentsToMatch(...) non-documented IAE Reviewed-by: sundar, mhaupt
author srastogi
date Mon, 06 Jun 2016 09:13:35 +0200
parents bed2bf575d93
children 6767ed99ea10 6286c38943db
files src/java.base/share/classes/java/lang/invoke/MethodHandles.java test/java/lang/invoke/DropArgumentsTest.java
diffstat 2 files changed, 13 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.base/share/classes/java/lang/invoke/MethodHandles.java	Fri Jun 03 17:01:23 2016 -0700
+++ b/src/java.base/share/classes/java/lang/invoke/MethodHandles.java	Mon Jun 06 09:13:35 2016 +0200
@@ -3360,9 +3360,9 @@
      * @param pos place in {@code newTypes} where the non-skipped target parameters must occur
      * @return a possibly adapted method handle
      * @throws NullPointerException if either argument is null
-     * @throws IllegalArgumentException
-     *         if either index is out of range in its corresponding list, or
-     *         if the non-skipped target parameter types match the new types at {@code pos}
+     * @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 the non-skipped target parameter types match the new types at {@code pos}
      * @since 9
      */
     public static
--- a/test/java/lang/invoke/DropArgumentsTest.java	Fri Jun 03 17:01:23 2016 -0700
+++ b/test/java/lang/invoke/DropArgumentsTest.java	Mon Jun 06 09:13:35 2016 +0200
@@ -25,7 +25,7 @@
 
 /* @test
  * @summary unit tests for java.lang.invoke.MethodHandles
- * @run testng/othervm -ea -esa test.java.lang.invoke.DropArgumentsTest
+ * @run testng test.java.lang.invoke.DropArgumentsTest
  */
 package test.java.lang.invoke;
 
@@ -87,4 +87,13 @@
     public void dropArgumentsToMatchIAE(MethodHandle target, int pos, List<Class<?>> valueType, int skip) {
         MethodHandles.dropArgumentsToMatch(target, pos, valueType , skip);
     }
+
+    @Test
+    @ExpectedExceptions(IllegalArgumentException.class)
+    public void dropArgumentsToMatchTestWithVoid() throws Throwable {
+        MethodHandle cat = lookup().findVirtual(String.class, "concat",
+                                   MethodType.methodType(String.class, String.class));
+        MethodType bigTypewithVoid = cat.type().insertParameterTypes(0, void.class, String.class, int.class);
+        MethodHandle handle2 = MethodHandles.dropArgumentsToMatch(cat, 0, bigTypewithVoid.parameterList(), 1);
+    }
 }