test/jdk/java/lang/invoke/InvokeMethodHandleWithBadArgument.java
author vlivanov
Tue, 26 Nov 2019 16:09:17 +0300
changeset 59275 a6e25566cb56
parent 47856 76519338df34
permissions -rw-r--r--
8234401: ConstantCallSite may stuck in non-frozen state Reviewed-by: psandoz
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
47856
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
     1
/*
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
     2
 * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
     4
 *
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
    10
 *
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
    15
 * accompanied this code).
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
    16
 *
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
    20
 *
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
    23
 * questions.
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
    24
 */
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
    25
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
    26
/*
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
    27
 * @test
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
    28
 * @bug 8157246
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
    29
 * @summary Tests invocation of MethodHandle with invalid leading argument
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
    30
 * @run testng/othervm test.java.lang.invoke.InvokeMethodHandleWithBadArgument
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
    31
 */
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
    32
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
    33
package test.java.lang.invoke;
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
    34
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
    35
import java.lang.invoke.MethodHandle;
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
    36
import java.lang.invoke.MethodHandles;
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
    37
import java.lang.invoke.MethodHandles.Lookup;
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
    38
import java.lang.invoke.MethodType;
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
    39
import java.lang.invoke.VarHandle;
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
    40
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
    41
import static java.lang.invoke.MethodType.methodType;
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
    42
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
    43
import static org.testng.AssertJUnit.*;
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
    44
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
    45
import org.testng.annotations.*;
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
    46
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
    47
/**
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
    48
 * Tests invocation of MethodHandle with invalid leading argument such as
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
    49
 * MethodHandle, VarHandle, and array object
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
    50
 */
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
    51
public class InvokeMethodHandleWithBadArgument {
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
    52
    // ---- null array reference ----
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
    53
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
    54
    @Test(expectedExceptions = {NullPointerException.class})
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
    55
    public static void testAsSpreaderPosInvokeWithNull() throws Throwable {
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
    56
        MethodHandle spreader = MH_spread.asSpreader(1, int[].class, 3);
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
    57
        spreader.invoke("A", null, "B");
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
    58
    }
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
    59
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
    60
    @Test(expectedExceptions = {NullPointerException.class})
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
    61
    public static void testAsSpreaderInvokeWithNull() throws Throwable {
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
    62
        MethodHandle spreader = MH_String_equals.asSpreader(String[].class, 2);
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
    63
        assert ((boolean) spreader.invokeExact(new String[]{"me", "me"}));
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
    64
        boolean eq = (boolean) spreader.invokeExact((String[]) null);
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
    65
    }
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
    66
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
    67
    // ---- incorrect array element count ----
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
    68
    @Test(expectedExceptions = {IllegalArgumentException.class})
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
    69
    public static void testAsSpreaderPosInvokeWithBadElementCount() throws Throwable {
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
    70
        MethodHandle spreader = MH_spread.asSpreader(1, int[].class, 3);
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
    71
        spreader.invoke("A", new int[]{1, 2}, "B");
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
    72
    }
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
    73
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
    74
    @Test(expectedExceptions = {IllegalArgumentException.class})
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
    75
    public static void testAsSpreaderInvokeWithBadElementCount() throws Throwable {
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
    76
        MethodHandle spreader = MH_String_equals.asSpreader(String[].class, 2);
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
    77
        assert (!(boolean) spreader.invokeExact(new String[]{"me", "thee"}));
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
    78
        boolean eq = (boolean) spreader.invokeExact(new String[0]);
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
    79
    }
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
    80
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
    81
    // ---- spread no argument ----
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
    82
    @Test
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
    83
    public static void testAsSpreaderPosInvokeWithZeroLength() throws Throwable {
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
    84
        MethodHandle spreader = MH_spread.asSpreader(1, int[].class, 0);
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
    85
        assert("A123B".equals(spreader.invoke("A", (int[])null, 1, 2, 3, "B")));
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
    86
    }
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
    87
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
    88
    @Test
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
    89
    public static void testAsSpreaderInvokeWithZeroLength() throws Throwable {
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
    90
        MethodHandle spreader = MH_String_equals.asSpreader(String[].class, 0);
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
    91
        assert ((boolean) spreader.invokeExact("me", (Object)"me", new String[0]));
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
    92
        boolean eq = (boolean) spreader.invokeExact("me", (Object)"me", (String[]) null);
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
    93
    }
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
    94
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
    95
    // ---- invokers with null method/var handle argument ----
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
    96
    @Test(expectedExceptions = {NullPointerException.class})
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
    97
    public static void testInvokerWithNull() throws Throwable {
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
    98
        MethodType type = methodType(int.class, int.class, int.class);
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
    99
        MethodHandle invoker = MethodHandles.invoker(type);
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
   100
        assert((int) invoker.invoke(MH_add, 1, 2) == 3);
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
   101
        int sum = (int)invoker.invoke((MethodHandle)null, 1, 2);
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
   102
    }
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
   103
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
   104
    @Test(expectedExceptions = {NullPointerException.class})
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
   105
    public static void testExactInvokerWithNull() throws Throwable {
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
   106
        MethodType type = methodType(int.class, int.class, int.class);
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
   107
        MethodHandle invoker = MethodHandles.exactInvoker(type);
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
   108
        assert((int) invoker.invoke(MH_add, 1, 2) == 3);
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
   109
        int sum = (int)invoker.invokeExact((MethodHandle)null, 1, 2);
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
   110
    }
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
   111
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
   112
    @Test(expectedExceptions = {NullPointerException.class})
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
   113
    public static void testSpreadInvokerWithNull() throws Throwable {
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
   114
        MethodType type = methodType(boolean.class, String.class, String.class);
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
   115
        MethodHandle invoker = MethodHandles.spreadInvoker(type, 0);
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
   116
        assert ((boolean) invoker.invoke(MH_String_equals, new String[]{"me", "me"}));
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
   117
        boolean eq = (boolean) invoker.invoke((MethodHandle)null, new String[]{"me", "me"});
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
   118
    }
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
   119
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
   120
    @Test(expectedExceptions = {NullPointerException.class})
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
   121
    public static void testVarHandleInvokerWithNull() throws Throwable {
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
   122
        VarHandle.AccessMode am = VarHandle.AccessMode.GET;
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
   123
        MethodHandle invoker = MethodHandles.varHandleInvoker(am, VH_array.accessModeType(am));
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
   124
        assert ((int) invoker.invoke(VH_array, array, 3) == 3);
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
   125
        int value = (int)invoker.invoke((VarHandle)null, array, 3);
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
   126
    }
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
   127
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
   128
    @Test(expectedExceptions = {NullPointerException.class})
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
   129
    public static void testVarHandleExactInvokerWithNull() throws Throwable {
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
   130
        VarHandle.AccessMode am = VarHandle.AccessMode.GET;
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
   131
        MethodHandle invoker = MethodHandles.varHandleExactInvoker(am, VH_array.accessModeType(am));
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
   132
        assert ((int) invoker.invoke(VH_array, array, 3) == 3);
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
   133
        int value = (int)invoker.invokeExact((VarHandle)null, array, 3);
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
   134
    }
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
   135
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
   136
    static final Lookup LOOKUP = MethodHandles.lookup();
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
   137
    static final MethodHandle MH_add;
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
   138
    static final MethodHandle MH_spread;
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
   139
    static final MethodHandle MH_String_equals;
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
   140
    static final VarHandle VH_array;
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
   141
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
   142
    static final int[] array = new int[] { 0, 1, 2, 3, 4, 5};
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
   143
    static {
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
   144
        try {
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
   145
            Class<?> arrayClass = Class.forName("[I");
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
   146
            VH_array = MethodHandles.arrayElementVarHandle(arrayClass);
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
   147
            MH_add = LOOKUP.findStatic(InvokeMethodHandleWithBadArgument.class, "add",
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
   148
                methodType(int.class, int.class, int.class));
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
   149
            MH_spread = LOOKUP.findStatic(InvokeMethodHandleWithBadArgument.class, "spread",
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
   150
                methodType(String.class, String.class, int.class, int.class, int.class, String.class));
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
   151
            MH_String_equals = LOOKUP.findVirtual(String.class, "equals", methodType(boolean.class, Object.class));
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
   152
        } catch (Exception e) {
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
   153
            throw new ExceptionInInitializerError(e);
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
   154
        }
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
   155
    }
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
   156
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
   157
    static String spread(String s1, int i1, int i2, int i3, String s2) {
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
   158
        return s1 + i1 + i2 + i3 + s2;
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
   159
    }
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
   160
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
   161
    static int add(int x, int y) {
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
   162
        return x+y;
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
   163
    }
76519338df34 8157246: MHs.arrayLength, arrayElementGetter/Setter, arrayConstructor need to specify invocation-time behavior
mchung
parents:
diff changeset
   164
}