test/jdk/java/lang/invoke/MethodHandlesArityLimitsTest.java
author vtheeyarath
Mon, 02 Jul 2018 23:33:40 -0700
changeset 50927 d99e206cc32e
permissions -rw-r--r--
8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods Summary: Updated spec and added tests Reviewed-by: psandoz
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
50927
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
     1
/*
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
     2
 * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
     4
 *
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
     7
 * published by the Free Software Foundation.
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
     8
 *
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
    13
 * accompanied this code).
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
    14
 *
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
    18
 *
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
    21
 * questions.
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
    22
 **/
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
    23
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
    24
/* @test
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
    25
 * @summary unit tests for arity limits of methods in java.lang.invoke.MethodHandles
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
    26
 * @run junit/othervm test.java.lang.invoke.MethodHandlesArityLimitsTest
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
    27
 **/
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
    28
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
    29
package test.java.lang.invoke;
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
    30
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
    31
import org.junit.*;
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
    32
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
    33
import java.lang.invoke.MethodHandles;
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
    34
import java.lang.invoke.MethodHandle;
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
    35
import java.lang.invoke.WrongMethodTypeException;
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
    36
import java.lang.invoke.MethodType;
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
    37
import java.lang.invoke.VarHandle;
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
    38
import java.util.List;
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
    39
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
    40
import java.util.stream.IntStream;
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
    41
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
    42
import static org.junit.Assert.*;
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
    43
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
    44
public class MethodHandlesArityLimitsTest {
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
    45
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
    46
    private static MethodType mt254 = null;
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
    47
    private static MethodType mt255 = null;
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
    48
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
    49
    static {
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
    50
        Class<?>[] classes254 = IntStream.range(0, 254)
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
    51
                                         .mapToObj(i -> int.class)
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
    52
                                         .toArray(Class[]::new);
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
    53
        mt254 = MethodType.methodType(void.class, classes254);
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
    54
        mt255 = mt254.appendParameterTypes(int.class);
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
    55
    }
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
    56
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
    57
    @Test(expected = IllegalArgumentException.class)
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
    58
    public void testDropArgumentsToMatch() {
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
    59
        MethodHandles.dropArgumentsToMatch(MethodHandles.empty(mt254), 0, mt255.parameterList(), 0);
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
    60
    }
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
    61
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
    62
    @Test(expected = IllegalArgumentException.class)
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
    63
    public void testEmpty() {
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
    64
        MethodHandles.empty(mt255);
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
    65
    }
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
    66
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
    67
    @Test(expected = IllegalArgumentException.class)
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
    68
    public void testExplicitCastArguments() {
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
    69
        MethodHandles.explicitCastArguments(
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
    70
                                         MethodHandles.empty(mt254),
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
    71
                                         mt254.dropParameterTypes(0, 1).insertParameterTypes(0, long.class) );
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
    72
    }
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
    73
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
    74
    @Test(expected = IllegalArgumentException.class)
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
    75
    public void testPermuteArguments() {
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
    76
        MethodHandles.permuteArguments(
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
    77
                                    MethodHandles.empty(MethodType.methodType(void.class)),
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
    78
                                    mt255);
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
    79
    }
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
    80
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
    81
    @Test(expected = IllegalArgumentException.class)
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
    82
    public void testVarHandleInvoker() {
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
    83
        MethodHandles.varHandleInvoker(VarHandle.AccessMode.GET, mt254);
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
    84
    }
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
    85
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
    86
    @Test(expected = IllegalArgumentException.class)
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
    87
    public void testVarHandleExactInvoker() {
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
    88
        MethodHandles.varHandleExactInvoker(VarHandle.AccessMode.GET, mt254);
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
    89
    }
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
    90
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
    91
    @Test(expected = IllegalArgumentException.class)
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
    92
    public void testMHExactInvoker() {
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
    93
        MethodHandles.exactInvoker(mt255);
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
    94
    }
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
    95
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
    96
    @Test(expected = IllegalArgumentException.class)
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
    97
    public void testMHInvoker() {
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
    98
        MethodHandles.invoker(mt255);
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
    99
    }
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
   100
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
   101
    @Test(expected = IllegalArgumentException.class)
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
   102
    public void testMHSpreadInvoker() {
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
   103
        MethodHandles.spreadInvoker(mt255, 255);
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
   104
    }
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
   105
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
   106
    @Test(expected = WrongMethodTypeException.class)
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
   107
    public void testAsType() throws ReflectiveOperationException {
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
   108
        MethodHandle asList = MethodHandles.lookup().findStatic(
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
   109
                                                java.util.Arrays.class,
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
   110
                                                "asList",
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
   111
                                                MethodType.methodType(List.class, Object[].class));
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
   112
        try {
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
   113
           asList.asType(MethodType.genericMethodType(254));//does not throw IAE or WMTE
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
   114
        }
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
   115
        catch(WrongMethodTypeException wmte) {
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
   116
           Assert.fail("Unexpected WrongMethodTypeException thrown");
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
   117
        }
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
   118
        asList.asType(MethodType.genericMethodType(255));//throws WMTE
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
   119
    }
d99e206cc32e 8177275: IllegalArgumentException when MH would have too many parameters is not specified for several methods
vtheeyarath
parents:
diff changeset
   120
}