< prev index next >

test/jdk/java/lang/invoke/VarHandles/VarHandleTestMethodTypeBoolean.java

Print this page

   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 


  24 /*
  25  * @test
  26  * @bug 8156486
  27  * @run testng/othervm VarHandleTestMethodTypeBoolean
  28  * @run testng/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=true -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true VarHandleTestMethodTypeBoolean
  29  * @run testng/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=false VarHandleTestMethodTypeBoolean
  30  * @run testng/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true VarHandleTestMethodTypeBoolean
  31  */
  32 
  33 import org.testng.annotations.BeforeClass;
  34 import org.testng.annotations.DataProvider;
  35 import org.testng.annotations.Test;
  36 
  37 import java.lang.invoke.MethodHandles;
  38 import java.lang.invoke.VarHandle;
  39 import java.util.ArrayList;
  40 import java.util.Arrays;
  41 import java.util.List;
  42 
  43 import static org.testng.Assert.*;
  44 
  45 import static java.lang.invoke.MethodType.*;
  46 
  47 public class VarHandleTestMethodTypeBoolean extends VarHandleBaseTest {


  48     static final boolean static_final_v = true;
  49 
  50     static boolean static_v = true;
  51 
  52     final boolean final_v = true;
  53 
  54     boolean v = true;
  55 
  56     VarHandle vhFinalField;
  57 
  58     VarHandle vhField;
  59 
  60     VarHandle vhStaticField;
  61 
  62     VarHandle vhStaticFinalField;
  63 
  64     VarHandle vhArray;
  65 
  66     @BeforeClass
  67     public void setup() throws Exception {
  68         vhFinalField = MethodHandles.lookup().findVarHandle(
  69                 VarHandleTestMethodTypeBoolean.class, "final_v", boolean.class);
  70 
  71         vhField = MethodHandles.lookup().findVarHandle(
  72                 VarHandleTestMethodTypeBoolean.class, "v", boolean.class);
  73 
  74         vhStaticFinalField = MethodHandles.lookup().findStaticVarHandle(
  75             VarHandleTestMethodTypeBoolean.class, "static_final_v", boolean.class);
  76 
  77         vhStaticField = MethodHandles.lookup().findStaticVarHandle(
  78             VarHandleTestMethodTypeBoolean.class, "static_v", boolean.class);
  79 
  80         vhArray = MethodHandles.arrayElementVarHandle(boolean[].class);
  81     }
  82 
  83     @DataProvider
  84     public Object[][] accessTestCaseProvider() throws Exception {
  85         List<AccessTestCase<?>> cases = new ArrayList<>();
  86 
  87         cases.add(new VarHandleAccessTestCase("Instance field",
  88                                               vhField, vh -> testInstanceFieldWrongMethodType(this, vh),
  89                                               false));
  90 
  91         cases.add(new VarHandleAccessTestCase("Static field",
  92                                               vhStaticField, VarHandleTestMethodTypeBoolean::testStaticFieldWrongMethodType,
  93                                               false));
  94 
  95         cases.add(new VarHandleAccessTestCase("Array",
  96                                               vhArray, VarHandleTestMethodTypeBoolean::testArrayWrongMethodType,
  97                                               false));
  98 

 900         // Incorrect return type
 901         checkWMTE(() -> { // reference class
 902             Void r = (Void) vh.getAndBitwiseXor(recv, true);
 903         });
 904         checkWMTE(() -> { // primitive class
 905             int x = (int) vh.getAndBitwiseXor(recv, true);
 906         });
 907         // Incorrect arity
 908         checkWMTE(() -> { // 0
 909             boolean x = (boolean) vh.getAndBitwiseXor();
 910         });
 911         checkWMTE(() -> { // >
 912             boolean x = (boolean) vh.getAndBitwiseXor(recv, true, Void.class);
 913         });
 914     }
 915 
 916     static void testInstanceFieldWrongMethodType(VarHandleTestMethodTypeBoolean recv, Handles hs) throws Throwable {
 917         for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET)) {
 918             // Incorrect argument types
 919             checkNPE(() -> { // null receiver
 920                 boolean x = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeBoolean.class)).
 921                     invokeExact((VarHandleTestMethodTypeBoolean) null);
 922             });
 923             hs.checkWMTEOrCCE(() -> { // receiver reference class
 924                 boolean x = (boolean) hs.get(am, methodType(boolean.class, Class.class)).
 925                     invokeExact(Void.class);
 926             });
 927             checkWMTE(() -> { // receiver primitive class
 928                 boolean x = (boolean) hs.get(am, methodType(boolean.class, int.class)).
 929                     invokeExact(0);
 930             });
 931             // Incorrect return type
 932             checkWMTE(() -> { // reference class
 933                 Void x = (Void) hs.get(am, methodType(Void.class, VarHandleTestMethodTypeBoolean.class)).
 934                     invokeExact(recv);
 935             });
 936             checkWMTE(() -> { // primitive class
 937                 int x = (int) hs.get(am, methodType(int.class, VarHandleTestMethodTypeBoolean.class)).
 938                     invokeExact(recv);
 939             });
 940             // Incorrect arity
 941             checkWMTE(() -> { // 0
 942                 boolean x = (boolean) hs.get(am, methodType(boolean.class)).
 943                     invokeExact();
 944             });
 945             checkWMTE(() -> { // >
 946                 boolean x = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeBoolean.class, Class.class)).
 947                     invokeExact(recv, Void.class);
 948             });
 949         }
 950 
 951         for (TestAccessMode am : testAccessModesOfType(TestAccessType.SET)) {
 952             // Incorrect argument types
 953             checkNPE(() -> { // null receiver
 954                 hs.get(am, methodType(void.class, VarHandleTestMethodTypeBoolean.class, boolean.class)).
 955                     invokeExact((VarHandleTestMethodTypeBoolean) null, true);
 956             });
 957             hs.checkWMTEOrCCE(() -> { // receiver reference class
 958                 hs.get(am, methodType(void.class, Class.class, boolean.class)).
 959                     invokeExact(Void.class, true);
 960             });
 961             checkWMTE(() -> { // value reference class
 962                 hs.get(am, methodType(void.class, VarHandleTestMethodTypeBoolean.class, Class.class)).
 963                     invokeExact(recv, Void.class);
 964             });
 965             checkWMTE(() -> { // receiver primitive class
 966                 hs.get(am, methodType(void.class, int.class, boolean.class)).
 967                     invokeExact(0, true);
 968             });
 969             // Incorrect arity
 970             checkWMTE(() -> { // 0
 971                 hs.get(am, methodType(void.class)).
 972                     invokeExact();
 973             });
 974             checkWMTE(() -> { // >
 975                 hs.get(am, methodType(void.class, VarHandleTestMethodTypeBoolean.class, boolean.class, Class.class)).
 976                     invokeExact(recv, true, Void.class);
 977             });
 978         }
 979 
 980         for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
 981             // Incorrect argument types
 982             checkNPE(() -> { // null receiver
 983                 boolean r = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeBoolean.class, boolean.class, boolean.class)).
 984                     invokeExact((VarHandleTestMethodTypeBoolean) null, true, true);
 985             });
 986             hs.checkWMTEOrCCE(() -> { // receiver reference class
 987                 boolean r = (boolean) hs.get(am, methodType(boolean.class, Class.class, boolean.class, boolean.class)).
 988                     invokeExact(Void.class, true, true);
 989             });
 990             checkWMTE(() -> { // expected reference class
 991                 boolean r = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeBoolean.class, Class.class, boolean.class)).
 992                     invokeExact(recv, Void.class, true);
 993             });
 994             checkWMTE(() -> { // actual reference class
 995                 boolean r = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeBoolean.class, boolean.class, Class.class)).
 996                     invokeExact(recv, true, Void.class);
 997             });
 998             checkWMTE(() -> { // receiver primitive class
 999                 boolean r = (boolean) hs.get(am, methodType(boolean.class, int.class , boolean.class, boolean.class)).
1000                     invokeExact(0, true, true);
1001             });
1002             // Incorrect arity
1003             checkWMTE(() -> { // 0
1004                 boolean r = (boolean) hs.get(am, methodType(boolean.class)).
1005                     invokeExact();
1006             });
1007             checkWMTE(() -> { // >
1008                 boolean r = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeBoolean.class, boolean.class, boolean.class, Class.class)).
1009                     invokeExact(recv, true, true, Void.class);
1010             });
1011         }
1012 
1013         for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
1014             checkNPE(() -> { // null receiver
1015                 boolean x = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeBoolean.class, boolean.class, boolean.class)).
1016                     invokeExact((VarHandleTestMethodTypeBoolean) null, true, true);
1017             });
1018             hs.checkWMTEOrCCE(() -> { // receiver reference class
1019                 boolean x = (boolean) hs.get(am, methodType(boolean.class, Class.class, boolean.class, boolean.class)).
1020                     invokeExact(Void.class, true, true);
1021             });
1022             checkWMTE(() -> { // expected reference class
1023                 boolean x = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeBoolean.class, Class.class, boolean.class)).
1024                     invokeExact(recv, Void.class, true);
1025             });
1026             checkWMTE(() -> { // actual reference class
1027                 boolean x = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeBoolean.class, boolean.class, Class.class)).
1028                     invokeExact(recv, true, Void.class);
1029             });
1030             checkWMTE(() -> { // reciever primitive class
1031                 boolean x = (boolean) hs.get(am, methodType(boolean.class, int.class , boolean.class, boolean.class)).
1032                     invokeExact(0, true, true);
1033             });
1034             // Incorrect return type
1035             checkWMTE(() -> { // reference class
1036                 Void r = (Void) hs.get(am, methodType(Void.class, VarHandleTestMethodTypeBoolean.class , boolean.class, boolean.class)).
1037                     invokeExact(recv, true, true);
1038             });
1039             checkWMTE(() -> { // primitive class
1040                 int x = (int) hs.get(am, methodType(int.class, VarHandleTestMethodTypeBoolean.class , boolean.class, boolean.class)).
1041                     invokeExact(recv, true, true);
1042             });
1043             // Incorrect arity
1044             checkWMTE(() -> { // 0
1045                 boolean x = (boolean) hs.get(am, methodType(boolean.class)).
1046                     invokeExact();
1047             });
1048             checkWMTE(() -> { // >
1049                 boolean x = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeBoolean.class, boolean.class, boolean.class, Class.class)).
1050                     invokeExact(recv, true, true, Void.class);
1051             });
1052         }
1053 
1054         for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
1055             checkNPE(() -> { // null receiver
1056                 boolean x = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeBoolean.class, boolean.class)).
1057                     invokeExact((VarHandleTestMethodTypeBoolean) null, true);
1058             });
1059             hs.checkWMTEOrCCE(() -> { // receiver reference class
1060                 boolean x = (boolean) hs.get(am, methodType(boolean.class, Class.class, boolean.class)).
1061                     invokeExact(Void.class, true);
1062             });
1063             checkWMTE(() -> { // value reference class
1064                 boolean x = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeBoolean.class, Class.class)).
1065                     invokeExact(recv, Void.class);
1066             });
1067             checkWMTE(() -> { // reciever primitive class
1068                 boolean x = (boolean) hs.get(am, methodType(boolean.class, int.class, boolean.class)).
1069                     invokeExact(0, true);
1070             });
1071             // Incorrect return type
1072             checkWMTE(() -> { // reference class
1073                 Void r = (Void) hs.get(am, methodType(Void.class, VarHandleTestMethodTypeBoolean.class, boolean.class)).
1074                     invokeExact(recv, true);
1075             });
1076             checkWMTE(() -> { // primitive class
1077                 int x = (int) hs.get(am, methodType(int.class, VarHandleTestMethodTypeBoolean.class, boolean.class)).
1078                     invokeExact(recv, true);
1079             });
1080             // Incorrect arity
1081             checkWMTE(() -> { // 0
1082                 boolean x = (boolean) hs.get(am, methodType(boolean.class)).
1083                     invokeExact();
1084             });
1085             checkWMTE(() -> { // >
1086                 boolean x = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeBoolean.class, boolean.class)).
1087                     invokeExact(recv, true, Void.class);
1088             });
1089         }
1090 
1091 
1092         for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_BITWISE)) {
1093             checkNPE(() -> { // null receiver
1094                 boolean x = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeBoolean.class, boolean.class)).
1095                     invokeExact((VarHandleTestMethodTypeBoolean) null, true);
1096             });
1097             hs.checkWMTEOrCCE(() -> { // receiver reference class
1098                 boolean x = (boolean) hs.get(am, methodType(boolean.class, Class.class, boolean.class)).
1099                     invokeExact(Void.class, true);
1100             });
1101             checkWMTE(() -> { // value reference class
1102                 boolean x = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeBoolean.class, Class.class)).
1103                     invokeExact(recv, Void.class);
1104             });
1105             checkWMTE(() -> { // reciever primitive class
1106                 boolean x = (boolean) hs.get(am, methodType(boolean.class, int.class, boolean.class)).
1107                     invokeExact(0, true);
1108             });
1109             // Incorrect return type
1110             checkWMTE(() -> { // reference class
1111                 Void r = (Void) hs.get(am, methodType(Void.class, VarHandleTestMethodTypeBoolean.class, boolean.class)).
1112                     invokeExact(recv, true);
1113             });
1114             checkWMTE(() -> { // primitive class
1115                 int x = (int) hs.get(am, methodType(int.class, VarHandleTestMethodTypeBoolean.class, boolean.class)).
1116                     invokeExact(recv, true);
1117             });
1118             // Incorrect arity
1119             checkWMTE(() -> { // 0
1120                 boolean x = (boolean) hs.get(am, methodType(boolean.class)).
1121                     invokeExact();
1122             });
1123             checkWMTE(() -> { // >
1124                 boolean x = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeBoolean.class, boolean.class)).
1125                     invokeExact(recv, true, Void.class);
1126             });
1127         }
1128     }
1129 
1130 
1131     static void testStaticFieldWrongMethodType(VarHandle vh) throws Throwable {
1132         // Get
1133         // Incorrect return type
1134         checkWMTE(() -> { // reference class
1135             Void x = (Void) vh.get();
1136         });
1137         checkWMTE(() -> { // primitive class
1138             int x = (int) vh.get();
1139         });
1140         // Incorrect arity
1141         checkWMTE(() -> { // >
1142             boolean x = (boolean) vh.get(Void.class);
1143         });
1144 

1661                     invokeExact();
1662             });
1663             // Incorrect arity
1664             checkWMTE(() -> { // >
1665                 boolean x = (boolean) hs.get(am, methodType(Class.class)).
1666                     invokeExact(Void.class);
1667             });
1668         }
1669 
1670         for (TestAccessMode am : testAccessModesOfType(TestAccessType.SET)) {
1671             checkWMTE(() -> { // value reference class
1672                 hs.get(am, methodType(void.class, Class.class)).
1673                     invokeExact(Void.class);
1674             });
1675             // Incorrect arity
1676             checkWMTE(() -> { // 0
1677                 hs.get(am, methodType(void.class)).
1678                     invokeExact();
1679             });
1680             checkWMTE(() -> { // >
1681                 hs.get(am, methodType(void.class, boolean.class, Class.class)).
1682                     invokeExact(true, Void.class);
1683             });
1684         }
1685         for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
1686             // Incorrect argument types
1687             checkWMTE(() -> { // expected reference class
1688                 boolean r = (boolean) hs.get(am, methodType(boolean.class, Class.class, boolean.class)).
1689                     invokeExact(Void.class, true);
1690             });
1691             checkWMTE(() -> { // actual reference class
1692                 boolean r = (boolean) hs.get(am, methodType(boolean.class, boolean.class, Class.class)).
1693                     invokeExact(true, Void.class);
1694             });
1695             // Incorrect arity
1696             checkWMTE(() -> { // 0
1697                 boolean r = (boolean) hs.get(am, methodType(boolean.class)).
1698                     invokeExact();
1699             });
1700             checkWMTE(() -> { // >
1701                 boolean r = (boolean) hs.get(am, methodType(boolean.class, boolean.class, boolean.class, Class.class)).
1702                     invokeExact(true, true, Void.class);
1703             });
1704         }
1705 
1706         for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
1707             // Incorrect argument types
1708             checkWMTE(() -> { // expected reference class
1709                 boolean x = (boolean) hs.get(am, methodType(boolean.class, Class.class, boolean.class)).
1710                     invokeExact(Void.class, true);
1711             });
1712             checkWMTE(() -> { // actual reference class
1713                 boolean x = (boolean) hs.get(am, methodType(boolean.class, boolean.class, Class.class)).
1714                     invokeExact(true, Void.class);
1715             });
1716             // Incorrect return type
1717             checkWMTE(() -> { // reference class
1718                 Void r = (Void) hs.get(am, methodType(Void.class, boolean.class, boolean.class)).
1719                     invokeExact(true, true);
1720             });
1721             checkWMTE(() -> { // primitive class
1722                 int x = (int) hs.get(am, methodType(int.class, boolean.class, boolean.class)).
1723                     invokeExact(true, true);
1724             });
1725             // Incorrect arity
1726             checkWMTE(() -> { // 0
1727                 boolean x = (boolean) hs.get(am, methodType(boolean.class)).
1728                     invokeExact();
1729             });
1730             checkWMTE(() -> { // >
1731                 boolean x = (boolean) hs.get(am, methodType(boolean.class, boolean.class, boolean.class, Class.class)).
1732                     invokeExact(true, true, Void.class);
1733             });
1734         }
1735 
1736         for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
1737             // Incorrect argument types
1738             checkWMTE(() -> { // value reference class
1739                 boolean x = (boolean) hs.get(am, methodType(boolean.class, Class.class)).
1740                     invokeExact(Void.class);
1741             });
1742             // Incorrect return type
1743             checkWMTE(() -> { // reference class
1744                 Void r = (Void) hs.get(am, methodType(Void.class, boolean.class)).
1745                     invokeExact(true);
1746             });
1747             checkWMTE(() -> { // primitive class
1748                 int x = (int) hs.get(am, methodType(int.class, boolean.class)).
1749                     invokeExact(true);
1750             });
1751             // Incorrect arity
1752             checkWMTE(() -> { // 0
1753                 boolean x = (boolean) hs.get(am, methodType(boolean.class)).
1754                     invokeExact();
1755             });
1756             checkWMTE(() -> { // >
1757                 boolean x = (boolean) hs.get(am, methodType(boolean.class, boolean.class, Class.class)).
1758                     invokeExact(true, Void.class);
1759             });
1760         }
1761 
1762 
1763         for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_BITWISE)) {
1764             // Incorrect argument types
1765             checkWMTE(() -> { // value reference class
1766                 boolean x = (boolean) hs.get(am, methodType(boolean.class, Class.class)).
1767                     invokeExact(Void.class);
1768             });
1769             // Incorrect return type
1770             checkWMTE(() -> { // reference class
1771                 Void r = (Void) hs.get(am, methodType(Void.class, boolean.class)).
1772                     invokeExact(true);
1773             });
1774             checkWMTE(() -> { // primitive class
1775                 int x = (int) hs.get(am, methodType(int.class, boolean.class)).
1776                     invokeExact(true);
1777             });
1778             // Incorrect arity
1779             checkWMTE(() -> { // 0
1780                 boolean x = (boolean) hs.get(am, methodType(boolean.class)).
1781                     invokeExact();
1782             });
1783             checkWMTE(() -> { // >
1784                 boolean x = (boolean) hs.get(am, methodType(boolean.class, boolean.class, Class.class)).
1785                     invokeExact(true, Void.class);
1786             });
1787         }
1788     }
1789 
1790 
1791     static void testArrayWrongMethodType(VarHandle vh) throws Throwable {
1792         boolean[] array = new boolean[10];
1793         Arrays.fill(array, true);
1794 
1795         // Get
1796         // Incorrect argument types
1797         checkNPE(() -> { // null array
1798             boolean x = (boolean) vh.get(null, 0);
1799         });
1800         checkCCE(() -> { // array reference class
1801             boolean x = (boolean) vh.get(Void.class, 0);
1802         });
1803         checkWMTE(() -> { // array primitive class
1804             boolean x = (boolean) vh.get(0, 0);

2655         });
2656         checkWMTE(() -> { // primitive class
2657             int x = (int) vh.getAndBitwiseXorRelease(array, 0, true);
2658         });
2659         // Incorrect arity
2660         checkWMTE(() -> { // 0
2661             boolean x = (boolean) vh.getAndBitwiseXorRelease();
2662         });
2663         checkWMTE(() -> { // >
2664             boolean x = (boolean) vh.getAndBitwiseXorRelease(array, 0, true, Void.class);
2665         });
2666     }
2667 
2668     static void testArrayWrongMethodType(Handles hs) throws Throwable {
2669         boolean[] array = new boolean[10];
2670         Arrays.fill(array, true);
2671 
2672         for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET)) {
2673             // Incorrect argument types
2674             checkNPE(() -> { // null array
2675                 boolean x = (boolean) hs.get(am, methodType(boolean.class, boolean[].class, int.class)).
2676                     invokeExact((boolean[]) null, 0);
2677             });
2678             hs.checkWMTEOrCCE(() -> { // array reference class
2679                 boolean x = (boolean) hs.get(am, methodType(boolean.class, Class.class, int.class)).
2680                     invokeExact(Void.class, 0);
2681             });
2682             checkWMTE(() -> { // array primitive class
2683                 boolean x = (boolean) hs.get(am, methodType(boolean.class, int.class, int.class)).
2684                     invokeExact(0, 0);
2685             });
2686             checkWMTE(() -> { // index reference class
2687                 boolean x = (boolean) hs.get(am, methodType(boolean.class, boolean[].class, Class.class)).
2688                     invokeExact(array, Void.class);
2689             });
2690             // Incorrect return type
2691             checkWMTE(() -> { // reference class
2692                 Void x = (Void) hs.get(am, methodType(Void.class, boolean[].class, int.class)).
2693                     invokeExact(array, 0);
2694             });
2695             checkWMTE(() -> { // primitive class
2696                 int x = (int) hs.get(am, methodType(int.class, boolean[].class, int.class)).
2697                     invokeExact(array, 0);
2698             });
2699             // Incorrect arity
2700             checkWMTE(() -> { // 0
2701                 boolean x = (boolean) hs.get(am, methodType(boolean.class)).
2702                     invokeExact();
2703             });
2704             checkWMTE(() -> { // >
2705                 boolean x = (boolean) hs.get(am, methodType(boolean.class, boolean[].class, int.class, Class.class)).
2706                     invokeExact(array, 0, Void.class);
2707             });
2708         }
2709 
2710         for (TestAccessMode am : testAccessModesOfType(TestAccessType.SET)) {
2711             // Incorrect argument types
2712             checkNPE(() -> { // null array
2713                 hs.get(am, methodType(void.class, boolean[].class, int.class, boolean.class)).
2714                     invokeExact((boolean[]) null, 0, true);
2715             });
2716             hs.checkWMTEOrCCE(() -> { // array reference class
2717                 hs.get(am, methodType(void.class, Class.class, int.class, boolean.class)).
2718                     invokeExact(Void.class, 0, true);
2719             });
2720             checkWMTE(() -> { // value reference class
2721                 hs.get(am, methodType(void.class, boolean[].class, int.class, Class.class)).
2722                     invokeExact(array, 0, Void.class);
2723             });
2724             checkWMTE(() -> { // receiver primitive class
2725                 hs.get(am, methodType(void.class, int.class, int.class, boolean.class)).
2726                     invokeExact(0, 0, true);
2727             });
2728             checkWMTE(() -> { // index reference class
2729                 hs.get(am, methodType(void.class, boolean[].class, Class.class, boolean.class)).
2730                     invokeExact(array, Void.class, true);
2731             });
2732             // Incorrect arity
2733             checkWMTE(() -> { // 0
2734                 hs.get(am, methodType(void.class)).
2735                     invokeExact();
2736             });
2737             checkWMTE(() -> { // >
2738                 hs.get(am, methodType(void.class, boolean[].class, int.class, Class.class)).
2739                     invokeExact(array, 0, true, Void.class);
2740             });
2741         }
2742         for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
2743             // Incorrect argument types
2744             checkNPE(() -> { // null receiver
2745                 boolean r = (boolean) hs.get(am, methodType(boolean.class, boolean[].class, int.class, boolean.class, boolean.class)).
2746                     invokeExact((boolean[]) null, 0, true, true);
2747             });
2748             hs.checkWMTEOrCCE(() -> { // receiver reference class
2749                 boolean r = (boolean) hs.get(am, methodType(boolean.class, Class.class, int.class, boolean.class, boolean.class)).
2750                     invokeExact(Void.class, 0, true, true);
2751             });
2752             checkWMTE(() -> { // expected reference class
2753                 boolean r = (boolean) hs.get(am, methodType(boolean.class, boolean[].class, int.class, Class.class, boolean.class)).
2754                     invokeExact(array, 0, Void.class, true);
2755             });
2756             checkWMTE(() -> { // actual reference class
2757                 boolean r = (boolean) hs.get(am, methodType(boolean.class, boolean[].class, int.class, boolean.class, Class.class)).
2758                     invokeExact(array, 0, true, Void.class);
2759             });
2760             checkWMTE(() -> { // receiver primitive class
2761                 boolean r = (boolean) hs.get(am, methodType(boolean.class, int.class, int.class, boolean.class, boolean.class)).
2762                     invokeExact(0, 0, true, true);
2763             });
2764             checkWMTE(() -> { // index reference class
2765                 boolean r = (boolean) hs.get(am, methodType(boolean.class, boolean[].class, Class.class, boolean.class, boolean.class)).
2766                     invokeExact(array, Void.class, true, true);
2767             });
2768             // Incorrect arity
2769             checkWMTE(() -> { // 0
2770                 boolean r = (boolean) hs.get(am, methodType(boolean.class)).
2771                     invokeExact();
2772             });
2773             checkWMTE(() -> { // >
2774                 boolean r = (boolean) hs.get(am, methodType(boolean.class, boolean[].class, int.class, boolean.class, boolean.class, Class.class)).
2775                     invokeExact(array, 0, true, true, Void.class);
2776             });
2777         }
2778 
2779         for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
2780             // Incorrect argument types
2781             checkNPE(() -> { // null receiver
2782                 boolean x = (boolean) hs.get(am, methodType(boolean.class, boolean[].class, int.class, boolean.class, boolean.class)).
2783                     invokeExact((boolean[]) null, 0, true, true);
2784             });
2785             hs.checkWMTEOrCCE(() -> { // array reference class
2786                 boolean x = (boolean) hs.get(am, methodType(boolean.class, Class.class, int.class, boolean.class, boolean.class)).
2787                     invokeExact(Void.class, 0, true, true);
2788             });
2789             checkWMTE(() -> { // expected reference class
2790                 boolean x = (boolean) hs.get(am, methodType(boolean.class, boolean[].class, int.class, Class.class, boolean.class)).
2791                     invokeExact(array, 0, Void.class, true);
2792             });
2793             checkWMTE(() -> { // actual reference class
2794                 boolean x = (boolean) hs.get(am, methodType(boolean.class, boolean[].class, int.class, boolean.class, Class.class)).
2795                     invokeExact(array, 0, true, Void.class);
2796             });
2797             checkWMTE(() -> { // array primitive class
2798                 boolean x = (boolean) hs.get(am, methodType(boolean.class, int.class, int.class, boolean.class, boolean.class)).
2799                     invokeExact(0, 0, true, true);
2800             });
2801             checkWMTE(() -> { // index reference class
2802                 boolean x = (boolean) hs.get(am, methodType(boolean.class, boolean[].class, Class.class, boolean.class, boolean.class)).
2803                     invokeExact(array, Void.class, true, true);
2804             });
2805             // Incorrect return type
2806             checkWMTE(() -> { // reference class
2807                 Void r = (Void) hs.get(am, methodType(Void.class, boolean[].class, int.class, boolean.class, boolean.class)).
2808                     invokeExact(array, 0, true, true);
2809             });
2810             checkWMTE(() -> { // primitive class
2811                 int x = (int) hs.get(am, methodType(int.class, boolean[].class, int.class, boolean.class, boolean.class)).
2812                     invokeExact(array, 0, true, true);
2813             });
2814             // Incorrect arity
2815             checkWMTE(() -> { // 0
2816                 boolean x = (boolean) hs.get(am, methodType(boolean.class)).
2817                     invokeExact();
2818             });
2819             checkWMTE(() -> { // >
2820                 boolean x = (boolean) hs.get(am, methodType(boolean.class, boolean[].class, int.class, boolean.class, boolean.class, Class.class)).
2821                     invokeExact(array, 0, true, true, Void.class);
2822             });
2823         }
2824 
2825         for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
2826             // Incorrect argument types
2827             checkNPE(() -> { // null array
2828                 boolean x = (boolean) hs.get(am, methodType(boolean.class, boolean[].class, int.class, boolean.class)).
2829                     invokeExact((boolean[]) null, 0, true);
2830             });
2831             hs.checkWMTEOrCCE(() -> { // array reference class
2832                 boolean x = (boolean) hs.get(am, methodType(boolean.class, Class.class, int.class, boolean.class)).
2833                     invokeExact(Void.class, 0, true);
2834             });
2835             checkWMTE(() -> { // value reference class
2836                 boolean x = (boolean) hs.get(am, methodType(boolean.class, boolean[].class, int.class, Class.class)).
2837                     invokeExact(array, 0, Void.class);
2838             });
2839             checkWMTE(() -> { // array primitive class
2840                 boolean x = (boolean) hs.get(am, methodType(boolean.class, int.class, int.class, boolean.class)).
2841                     invokeExact(0, 0, true);
2842             });
2843             checkWMTE(() -> { // index reference class
2844                 boolean x = (boolean) hs.get(am, methodType(boolean.class, boolean[].class, Class.class, boolean.class)).
2845                     invokeExact(array, Void.class, true);
2846             });
2847             // Incorrect return type
2848             checkWMTE(() -> { // reference class
2849                 Void r = (Void) hs.get(am, methodType(Void.class, boolean[].class, int.class, boolean.class)).
2850                     invokeExact(array, 0, true);
2851             });
2852             checkWMTE(() -> { // primitive class
2853                 int x = (int) hs.get(am, methodType(int.class, boolean[].class, int.class, boolean.class)).
2854                     invokeExact(array, 0, true);
2855             });
2856             // Incorrect arity
2857             checkWMTE(() -> { // 0
2858                 boolean x = (boolean) hs.get(am, methodType(boolean.class)).
2859                     invokeExact();
2860             });
2861             checkWMTE(() -> { // >
2862                 boolean x = (boolean) hs.get(am, methodType(boolean.class, boolean[].class, int.class, boolean.class, Class.class)).
2863                     invokeExact(array, 0, true, Void.class);
2864             });
2865         }
2866 
2867 
2868         for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_BITWISE)) {
2869             // Incorrect argument types
2870             checkNPE(() -> { // null array
2871                 boolean x = (boolean) hs.get(am, methodType(boolean.class, boolean[].class, int.class, boolean.class)).
2872                     invokeExact((boolean[]) null, 0, true);
2873             });
2874             hs.checkWMTEOrCCE(() -> { // array reference class
2875                 boolean x = (boolean) hs.get(am, methodType(boolean.class, Class.class, int.class, boolean.class)).
2876                     invokeExact(Void.class, 0, true);
2877             });
2878             checkWMTE(() -> { // value reference class
2879                 boolean x = (boolean) hs.get(am, methodType(boolean.class, boolean[].class, int.class, Class.class)).
2880                     invokeExact(array, 0, Void.class);
2881             });
2882             checkWMTE(() -> { // array primitive class
2883                 boolean x = (boolean) hs.get(am, methodType(boolean.class, int.class, int.class, boolean.class)).
2884                     invokeExact(0, 0, true);
2885             });
2886             checkWMTE(() -> { // index reference class
2887                 boolean x = (boolean) hs.get(am, methodType(boolean.class, boolean[].class, Class.class, boolean.class)).
2888                     invokeExact(array, Void.class, true);
2889             });
2890             // Incorrect return type
2891             checkWMTE(() -> { // reference class
2892                 Void r = (Void) hs.get(am, methodType(Void.class, boolean[].class, int.class, boolean.class)).
2893                     invokeExact(array, 0, true);
2894             });
2895             checkWMTE(() -> { // primitive class
2896                 int x = (int) hs.get(am, methodType(int.class, boolean[].class, int.class, boolean.class)).
2897                     invokeExact(array, 0, true);
2898             });
2899             // Incorrect arity
2900             checkWMTE(() -> { // 0
2901                 boolean x = (boolean) hs.get(am, methodType(boolean.class)).
2902                     invokeExact();
2903             });
2904             checkWMTE(() -> { // >
2905                 boolean x = (boolean) hs.get(am, methodType(boolean.class, boolean[].class, int.class, boolean.class, Class.class)).
2906                     invokeExact(array, 0, true, Void.class);
2907             });
2908         }
2909     }
2910 }

   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 // -- This file was mechanically generated: Do not edit! -- //
  25 
  26 /*
  27  * @test
  28  * @bug 8156486
  29  * @run testng/othervm VarHandleTestMethodTypeBoolean
  30  * @run testng/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=true -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true VarHandleTestMethodTypeBoolean
  31  * @run testng/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=false VarHandleTestMethodTypeBoolean
  32  * @run testng/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true VarHandleTestMethodTypeBoolean
  33  */
  34 
  35 import org.testng.annotations.BeforeClass;
  36 import org.testng.annotations.DataProvider;
  37 import org.testng.annotations.Test;
  38 
  39 import java.lang.invoke.MethodHandles;
  40 import java.lang.invoke.VarHandle;
  41 import java.util.ArrayList;
  42 import java.util.Arrays;
  43 import java.util.List;
  44 
  45 import static org.testng.Assert.*;
  46 
  47 import static java.lang.invoke.MethodType.*;
  48 
  49 public class VarHandleTestMethodTypeBoolean extends VarHandleBaseTest {
  50     static final Class<?> type = boolean.class;
  51 
  52     static final boolean static_final_v = true;
  53 
  54     static boolean static_v = true;
  55 
  56     final boolean final_v = true;
  57 
  58     boolean v = true;
  59 
  60     VarHandle vhFinalField;
  61 
  62     VarHandle vhField;
  63 
  64     VarHandle vhStaticField;
  65 
  66     VarHandle vhStaticFinalField;
  67 
  68     VarHandle vhArray;
  69 
  70     @BeforeClass
  71     public void setup() throws Exception {
  72         vhFinalField = MethodHandles.lookup().findVarHandle(
  73                 VarHandleTestMethodTypeBoolean.class, "final_v", type);
  74 
  75         vhField = MethodHandles.lookup().findVarHandle(
  76                 VarHandleTestMethodTypeBoolean.class, "v", type);
  77 
  78         vhStaticFinalField = MethodHandles.lookup().findStaticVarHandle(
  79             VarHandleTestMethodTypeBoolean.class, "static_final_v", type);
  80 
  81         vhStaticField = MethodHandles.lookup().findStaticVarHandle(
  82             VarHandleTestMethodTypeBoolean.class, "static_v", type);
  83 
  84         vhArray = MethodHandles.arrayElementVarHandle(boolean[].class);
  85     }
  86 
  87     @DataProvider
  88     public Object[][] accessTestCaseProvider() throws Exception {
  89         List<AccessTestCase<?>> cases = new ArrayList<>();
  90 
  91         cases.add(new VarHandleAccessTestCase("Instance field",
  92                                               vhField, vh -> testInstanceFieldWrongMethodType(this, vh),
  93                                               false));
  94 
  95         cases.add(new VarHandleAccessTestCase("Static field",
  96                                               vhStaticField, VarHandleTestMethodTypeBoolean::testStaticFieldWrongMethodType,
  97                                               false));
  98 
  99         cases.add(new VarHandleAccessTestCase("Array",
 100                                               vhArray, VarHandleTestMethodTypeBoolean::testArrayWrongMethodType,
 101                                               false));
 102 

 904         // Incorrect return type
 905         checkWMTE(() -> { // reference class
 906             Void r = (Void) vh.getAndBitwiseXor(recv, true);
 907         });
 908         checkWMTE(() -> { // primitive class
 909             int x = (int) vh.getAndBitwiseXor(recv, true);
 910         });
 911         // Incorrect arity
 912         checkWMTE(() -> { // 0
 913             boolean x = (boolean) vh.getAndBitwiseXor();
 914         });
 915         checkWMTE(() -> { // >
 916             boolean x = (boolean) vh.getAndBitwiseXor(recv, true, Void.class);
 917         });
 918     }
 919 
 920     static void testInstanceFieldWrongMethodType(VarHandleTestMethodTypeBoolean recv, Handles hs) throws Throwable {
 921         for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET)) {
 922             // Incorrect argument types
 923             checkNPE(() -> { // null receiver
 924                 boolean x = (boolean) hs.get(am, methodType(type, VarHandleTestMethodTypeBoolean.class)).
 925                     invokeExact((VarHandleTestMethodTypeBoolean) null);
 926             });
 927             hs.checkWMTEOrCCE(() -> { // receiver reference class
 928                 boolean x = (boolean) hs.get(am, methodType(type, Class.class)).
 929                     invokeExact(Void.class);
 930             });
 931             checkWMTE(() -> { // receiver primitive class
 932                 boolean x = (boolean) hs.get(am, methodType(type, int.class)).
 933                     invokeExact(0);
 934             });
 935             // Incorrect return type
 936             checkWMTE(() -> { // reference class
 937                 Void x = (Void) hs.get(am, methodType(Void.class, VarHandleTestMethodTypeBoolean.class)).
 938                     invokeExact(recv);
 939             });
 940             checkWMTE(() -> { // primitive class
 941                 int x = (int) hs.get(am, methodType(int.class, VarHandleTestMethodTypeBoolean.class)).
 942                     invokeExact(recv);
 943             });
 944             // Incorrect arity
 945             checkWMTE(() -> { // 0
 946                 boolean x = (boolean) hs.get(am, methodType(type)).
 947                     invokeExact();
 948             });
 949             checkWMTE(() -> { // >
 950                 boolean x = (boolean) hs.get(am, methodType(type, VarHandleTestMethodTypeBoolean.class, Class.class)).
 951                     invokeExact(recv, Void.class);
 952             });
 953         }
 954 
 955         for (TestAccessMode am : testAccessModesOfType(TestAccessType.SET)) {
 956             // Incorrect argument types
 957             checkNPE(() -> { // null receiver
 958                 hs.get(am, methodType(void.class, VarHandleTestMethodTypeBoolean.class, type)).
 959                     invokeExact((VarHandleTestMethodTypeBoolean) null, true);
 960             });
 961             hs.checkWMTEOrCCE(() -> { // receiver reference class
 962                 hs.get(am, methodType(void.class, Class.class, type)).
 963                     invokeExact(Void.class, true);
 964             });
 965             checkWMTE(() -> { // value reference class
 966                 hs.get(am, methodType(void.class, VarHandleTestMethodTypeBoolean.class, Class.class)).
 967                     invokeExact(recv, Void.class);
 968             });
 969             checkWMTE(() -> { // receiver primitive class
 970                 hs.get(am, methodType(void.class, int.class, type)).
 971                     invokeExact(0, true);
 972             });
 973             // Incorrect arity
 974             checkWMTE(() -> { // 0
 975                 hs.get(am, methodType(void.class)).
 976                     invokeExact();
 977             });
 978             checkWMTE(() -> { // >
 979                 hs.get(am, methodType(void.class, VarHandleTestMethodTypeBoolean.class, type, Class.class)).
 980                     invokeExact(recv, true, Void.class);
 981             });
 982         }
 983 
 984         for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
 985             // Incorrect argument types
 986             checkNPE(() -> { // null receiver
 987                 boolean r = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeBoolean.class, type, type)).
 988                     invokeExact((VarHandleTestMethodTypeBoolean) null, true, true);
 989             });
 990             hs.checkWMTEOrCCE(() -> { // receiver reference class
 991                 boolean r = (boolean) hs.get(am, methodType(boolean.class, Class.class, type, type)).
 992                     invokeExact(Void.class, true, true);
 993             });
 994             checkWMTE(() -> { // expected reference class
 995                 boolean r = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeBoolean.class, Class.class, type)).
 996                     invokeExact(recv, Void.class, true);
 997             });
 998             checkWMTE(() -> { // actual reference class
 999                 boolean r = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeBoolean.class, type, Class.class)).
1000                     invokeExact(recv, true, Void.class);
1001             });
1002             checkWMTE(() -> { // receiver primitive class
1003                 boolean r = (boolean) hs.get(am, methodType(boolean.class, int.class , type, type)).
1004                     invokeExact(0, true, true);
1005             });
1006             // Incorrect arity
1007             checkWMTE(() -> { // 0
1008                 boolean r = (boolean) hs.get(am, methodType(boolean.class)).
1009                     invokeExact();
1010             });
1011             checkWMTE(() -> { // >
1012                 boolean r = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeBoolean.class, type, type, Class.class)).
1013                     invokeExact(recv, true, true, Void.class);
1014             });
1015         }
1016 
1017         for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
1018             checkNPE(() -> { // null receiver
1019                 boolean x = (boolean) hs.get(am, methodType(type, VarHandleTestMethodTypeBoolean.class, type, type)).
1020                     invokeExact((VarHandleTestMethodTypeBoolean) null, true, true);
1021             });
1022             hs.checkWMTEOrCCE(() -> { // receiver reference class
1023                 boolean x = (boolean) hs.get(am, methodType(type, Class.class, type, type)).
1024                     invokeExact(Void.class, true, true);
1025             });
1026             checkWMTE(() -> { // expected reference class
1027                 boolean x = (boolean) hs.get(am, methodType(type, VarHandleTestMethodTypeBoolean.class, Class.class, type)).
1028                     invokeExact(recv, Void.class, true);
1029             });
1030             checkWMTE(() -> { // actual reference class
1031                 boolean x = (boolean) hs.get(am, methodType(type, VarHandleTestMethodTypeBoolean.class, type, Class.class)).
1032                     invokeExact(recv, true, Void.class);
1033             });
1034             checkWMTE(() -> { // reciever primitive class
1035                 boolean x = (boolean) hs.get(am, methodType(type, int.class , type, type)).
1036                     invokeExact(0, true, true);
1037             });
1038             // Incorrect return type
1039             checkWMTE(() -> { // reference class
1040                 Void r = (Void) hs.get(am, methodType(Void.class, VarHandleTestMethodTypeBoolean.class , type, type)).
1041                     invokeExact(recv, true, true);
1042             });
1043             checkWMTE(() -> { // primitive class
1044                 int x = (int) hs.get(am, methodType(int.class, VarHandleTestMethodTypeBoolean.class , type, type)).
1045                     invokeExact(recv, true, true);
1046             });
1047             // Incorrect arity
1048             checkWMTE(() -> { // 0
1049                 boolean x = (boolean) hs.get(am, methodType(type)).
1050                     invokeExact();
1051             });
1052             checkWMTE(() -> { // >
1053                 boolean x = (boolean) hs.get(am, methodType(type, VarHandleTestMethodTypeBoolean.class, type, type, Class.class)).
1054                     invokeExact(recv, true, true, Void.class);
1055             });
1056         }
1057 
1058         for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
1059             checkNPE(() -> { // null receiver
1060                 boolean x = (boolean) hs.get(am, methodType(type, VarHandleTestMethodTypeBoolean.class, type)).
1061                     invokeExact((VarHandleTestMethodTypeBoolean) null, true);
1062             });
1063             hs.checkWMTEOrCCE(() -> { // receiver reference class
1064                 boolean x = (boolean) hs.get(am, methodType(type, Class.class, type)).
1065                     invokeExact(Void.class, true);
1066             });
1067             checkWMTE(() -> { // value reference class
1068                 boolean x = (boolean) hs.get(am, methodType(type, VarHandleTestMethodTypeBoolean.class, Class.class)).
1069                     invokeExact(recv, Void.class);
1070             });
1071             checkWMTE(() -> { // reciever primitive class
1072                 boolean x = (boolean) hs.get(am, methodType(type, int.class, type)).
1073                     invokeExact(0, true);
1074             });
1075             // Incorrect return type
1076             checkWMTE(() -> { // reference class
1077                 Void r = (Void) hs.get(am, methodType(Void.class, VarHandleTestMethodTypeBoolean.class, type)).
1078                     invokeExact(recv, true);
1079             });
1080             checkWMTE(() -> { // primitive class
1081                 int x = (int) hs.get(am, methodType(int.class, VarHandleTestMethodTypeBoolean.class, type)).
1082                     invokeExact(recv, true);
1083             });
1084             // Incorrect arity
1085             checkWMTE(() -> { // 0
1086                 boolean x = (boolean) hs.get(am, methodType(type)).
1087                     invokeExact();
1088             });
1089             checkWMTE(() -> { // >
1090                 boolean x = (boolean) hs.get(am, methodType(type, VarHandleTestMethodTypeBoolean.class, type)).
1091                     invokeExact(recv, true, Void.class);
1092             });
1093         }
1094 
1095 
1096         for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_BITWISE)) {
1097             checkNPE(() -> { // null receiver
1098                 boolean x = (boolean) hs.get(am, methodType(type, VarHandleTestMethodTypeBoolean.class, type)).
1099                     invokeExact((VarHandleTestMethodTypeBoolean) null, true);
1100             });
1101             hs.checkWMTEOrCCE(() -> { // receiver reference class
1102                 boolean x = (boolean) hs.get(am, methodType(type, Class.class, type)).
1103                     invokeExact(Void.class, true);
1104             });
1105             checkWMTE(() -> { // value reference class
1106                 boolean x = (boolean) hs.get(am, methodType(type, VarHandleTestMethodTypeBoolean.class, Class.class)).
1107                     invokeExact(recv, Void.class);
1108             });
1109             checkWMTE(() -> { // reciever primitive class
1110                 boolean x = (boolean) hs.get(am, methodType(type, int.class, type)).
1111                     invokeExact(0, true);
1112             });
1113             // Incorrect return type
1114             checkWMTE(() -> { // reference class
1115                 Void r = (Void) hs.get(am, methodType(Void.class, VarHandleTestMethodTypeBoolean.class, type)).
1116                     invokeExact(recv, true);
1117             });
1118             checkWMTE(() -> { // primitive class
1119                 int x = (int) hs.get(am, methodType(int.class, VarHandleTestMethodTypeBoolean.class, type)).
1120                     invokeExact(recv, true);
1121             });
1122             // Incorrect arity
1123             checkWMTE(() -> { // 0
1124                 boolean x = (boolean) hs.get(am, methodType(type)).
1125                     invokeExact();
1126             });
1127             checkWMTE(() -> { // >
1128                 boolean x = (boolean) hs.get(am, methodType(type, VarHandleTestMethodTypeBoolean.class, type)).
1129                     invokeExact(recv, true, Void.class);
1130             });
1131         }
1132     }
1133 
1134 
1135     static void testStaticFieldWrongMethodType(VarHandle vh) throws Throwable {
1136         // Get
1137         // Incorrect return type
1138         checkWMTE(() -> { // reference class
1139             Void x = (Void) vh.get();
1140         });
1141         checkWMTE(() -> { // primitive class
1142             int x = (int) vh.get();
1143         });
1144         // Incorrect arity
1145         checkWMTE(() -> { // >
1146             boolean x = (boolean) vh.get(Void.class);
1147         });
1148 

1665                     invokeExact();
1666             });
1667             // Incorrect arity
1668             checkWMTE(() -> { // >
1669                 boolean x = (boolean) hs.get(am, methodType(Class.class)).
1670                     invokeExact(Void.class);
1671             });
1672         }
1673 
1674         for (TestAccessMode am : testAccessModesOfType(TestAccessType.SET)) {
1675             checkWMTE(() -> { // value reference class
1676                 hs.get(am, methodType(void.class, Class.class)).
1677                     invokeExact(Void.class);
1678             });
1679             // Incorrect arity
1680             checkWMTE(() -> { // 0
1681                 hs.get(am, methodType(void.class)).
1682                     invokeExact();
1683             });
1684             checkWMTE(() -> { // >
1685                 hs.get(am, methodType(void.class, type, Class.class)).
1686                     invokeExact(true, Void.class);
1687             });
1688         }
1689         for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
1690             // Incorrect argument types
1691             checkWMTE(() -> { // expected reference class
1692                 boolean r = (boolean) hs.get(am, methodType(boolean.class, Class.class, type)).
1693                     invokeExact(Void.class, true);
1694             });
1695             checkWMTE(() -> { // actual reference class
1696                 boolean r = (boolean) hs.get(am, methodType(boolean.class, type, Class.class)).
1697                     invokeExact(true, Void.class);
1698             });
1699             // Incorrect arity
1700             checkWMTE(() -> { // 0
1701                 boolean r = (boolean) hs.get(am, methodType(boolean.class)).
1702                     invokeExact();
1703             });
1704             checkWMTE(() -> { // >
1705                 boolean r = (boolean) hs.get(am, methodType(boolean.class, type, type, Class.class)).
1706                     invokeExact(true, true, Void.class);
1707             });
1708         }
1709 
1710         for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
1711             // Incorrect argument types
1712             checkWMTE(() -> { // expected reference class
1713                 boolean x = (boolean) hs.get(am, methodType(type, Class.class, type)).
1714                     invokeExact(Void.class, true);
1715             });
1716             checkWMTE(() -> { // actual reference class
1717                 boolean x = (boolean) hs.get(am, methodType(type, type, Class.class)).
1718                     invokeExact(true, Void.class);
1719             });
1720             // Incorrect return type
1721             checkWMTE(() -> { // reference class
1722                 Void r = (Void) hs.get(am, methodType(Void.class, type, type)).
1723                     invokeExact(true, true);
1724             });
1725             checkWMTE(() -> { // primitive class
1726                 int x = (int) hs.get(am, methodType(int.class, type, type)).
1727                     invokeExact(true, true);
1728             });
1729             // Incorrect arity
1730             checkWMTE(() -> { // 0
1731                 boolean x = (boolean) hs.get(am, methodType(type)).
1732                     invokeExact();
1733             });
1734             checkWMTE(() -> { // >
1735                 boolean x = (boolean) hs.get(am, methodType(type, type, type, Class.class)).
1736                     invokeExact(true, true, Void.class);
1737             });
1738         }
1739 
1740         for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
1741             // Incorrect argument types
1742             checkWMTE(() -> { // value reference class
1743                 boolean x = (boolean) hs.get(am, methodType(type, Class.class)).
1744                     invokeExact(Void.class);
1745             });
1746             // Incorrect return type
1747             checkWMTE(() -> { // reference class
1748                 Void r = (Void) hs.get(am, methodType(Void.class, type)).
1749                     invokeExact(true);
1750             });
1751             checkWMTE(() -> { // primitive class
1752                 int x = (int) hs.get(am, methodType(int.class, type)).
1753                     invokeExact(true);
1754             });
1755             // Incorrect arity
1756             checkWMTE(() -> { // 0
1757                 boolean x = (boolean) hs.get(am, methodType(type)).
1758                     invokeExact();
1759             });
1760             checkWMTE(() -> { // >
1761                 boolean x = (boolean) hs.get(am, methodType(type, type, Class.class)).
1762                     invokeExact(true, Void.class);
1763             });
1764         }
1765 
1766 
1767         for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_BITWISE)) {
1768             // Incorrect argument types
1769             checkWMTE(() -> { // value reference class
1770                 boolean x = (boolean) hs.get(am, methodType(type, Class.class)).
1771                     invokeExact(Void.class);
1772             });
1773             // Incorrect return type
1774             checkWMTE(() -> { // reference class
1775                 Void r = (Void) hs.get(am, methodType(Void.class, type)).
1776                     invokeExact(true);
1777             });
1778             checkWMTE(() -> { // primitive class
1779                 int x = (int) hs.get(am, methodType(int.class, type)).
1780                     invokeExact(true);
1781             });
1782             // Incorrect arity
1783             checkWMTE(() -> { // 0
1784                 boolean x = (boolean) hs.get(am, methodType(type)).
1785                     invokeExact();
1786             });
1787             checkWMTE(() -> { // >
1788                 boolean x = (boolean) hs.get(am, methodType(type, type, Class.class)).
1789                     invokeExact(true, Void.class);
1790             });
1791         }
1792     }
1793 
1794 
1795     static void testArrayWrongMethodType(VarHandle vh) throws Throwable {
1796         boolean[] array = new boolean[10];
1797         Arrays.fill(array, true);
1798 
1799         // Get
1800         // Incorrect argument types
1801         checkNPE(() -> { // null array
1802             boolean x = (boolean) vh.get(null, 0);
1803         });
1804         checkCCE(() -> { // array reference class
1805             boolean x = (boolean) vh.get(Void.class, 0);
1806         });
1807         checkWMTE(() -> { // array primitive class
1808             boolean x = (boolean) vh.get(0, 0);

2659         });
2660         checkWMTE(() -> { // primitive class
2661             int x = (int) vh.getAndBitwiseXorRelease(array, 0, true);
2662         });
2663         // Incorrect arity
2664         checkWMTE(() -> { // 0
2665             boolean x = (boolean) vh.getAndBitwiseXorRelease();
2666         });
2667         checkWMTE(() -> { // >
2668             boolean x = (boolean) vh.getAndBitwiseXorRelease(array, 0, true, Void.class);
2669         });
2670     }
2671 
2672     static void testArrayWrongMethodType(Handles hs) throws Throwable {
2673         boolean[] array = new boolean[10];
2674         Arrays.fill(array, true);
2675 
2676         for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET)) {
2677             // Incorrect argument types
2678             checkNPE(() -> { // null array
2679                 boolean x = (boolean) hs.get(am, methodType(type, boolean[].class, int.class)).
2680                     invokeExact((boolean[]) null, 0);
2681             });
2682             hs.checkWMTEOrCCE(() -> { // array reference class
2683                 boolean x = (boolean) hs.get(am, methodType(type, Class.class, int.class)).
2684                     invokeExact(Void.class, 0);
2685             });
2686             checkWMTE(() -> { // array primitive class
2687                 boolean x = (boolean) hs.get(am, methodType(type, int.class, int.class)).
2688                     invokeExact(0, 0);
2689             });
2690             checkWMTE(() -> { // index reference class
2691                 boolean x = (boolean) hs.get(am, methodType(type, boolean[].class, Class.class)).
2692                     invokeExact(array, Void.class);
2693             });
2694             // Incorrect return type
2695             checkWMTE(() -> { // reference class
2696                 Void x = (Void) hs.get(am, methodType(Void.class, boolean[].class, int.class)).
2697                     invokeExact(array, 0);
2698             });
2699             checkWMTE(() -> { // primitive class
2700                 int x = (int) hs.get(am, methodType(int.class, boolean[].class, int.class)).
2701                     invokeExact(array, 0);
2702             });
2703             // Incorrect arity
2704             checkWMTE(() -> { // 0
2705                 boolean x = (boolean) hs.get(am, methodType(type)).
2706                     invokeExact();
2707             });
2708             checkWMTE(() -> { // >
2709                 boolean x = (boolean) hs.get(am, methodType(type, boolean[].class, int.class, Class.class)).
2710                     invokeExact(array, 0, Void.class);
2711             });
2712         }
2713 
2714         for (TestAccessMode am : testAccessModesOfType(TestAccessType.SET)) {
2715             // Incorrect argument types
2716             checkNPE(() -> { // null array
2717                 hs.get(am, methodType(void.class, boolean[].class, int.class, type)).
2718                     invokeExact((boolean[]) null, 0, true);
2719             });
2720             hs.checkWMTEOrCCE(() -> { // array reference class
2721                 hs.get(am, methodType(void.class, Class.class, int.class, type)).
2722                     invokeExact(Void.class, 0, true);
2723             });
2724             checkWMTE(() -> { // value reference class
2725                 hs.get(am, methodType(void.class, boolean[].class, int.class, Class.class)).
2726                     invokeExact(array, 0, Void.class);
2727             });
2728             checkWMTE(() -> { // receiver primitive class
2729                 hs.get(am, methodType(void.class, int.class, int.class, type)).
2730                     invokeExact(0, 0, true);
2731             });
2732             checkWMTE(() -> { // index reference class
2733                 hs.get(am, methodType(void.class, boolean[].class, Class.class, type)).
2734                     invokeExact(array, Void.class, true);
2735             });
2736             // Incorrect arity
2737             checkWMTE(() -> { // 0
2738                 hs.get(am, methodType(void.class)).
2739                     invokeExact();
2740             });
2741             checkWMTE(() -> { // >
2742                 hs.get(am, methodType(void.class, boolean[].class, int.class, Class.class)).
2743                     invokeExact(array, 0, true, Void.class);
2744             });
2745         }
2746         for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
2747             // Incorrect argument types
2748             checkNPE(() -> { // null receiver
2749                 boolean r = (boolean) hs.get(am, methodType(boolean.class, boolean[].class, int.class, type, type)).
2750                     invokeExact((boolean[]) null, 0, true, true);
2751             });
2752             hs.checkWMTEOrCCE(() -> { // receiver reference class
2753                 boolean r = (boolean) hs.get(am, methodType(boolean.class, Class.class, int.class, type, type)).
2754                     invokeExact(Void.class, 0, true, true);
2755             });
2756             checkWMTE(() -> { // expected reference class
2757                 boolean r = (boolean) hs.get(am, methodType(boolean.class, boolean[].class, int.class, Class.class, type)).
2758                     invokeExact(array, 0, Void.class, true);
2759             });
2760             checkWMTE(() -> { // actual reference class
2761                 boolean r = (boolean) hs.get(am, methodType(boolean.class, boolean[].class, int.class, type, Class.class)).
2762                     invokeExact(array, 0, true, Void.class);
2763             });
2764             checkWMTE(() -> { // receiver primitive class
2765                 boolean r = (boolean) hs.get(am, methodType(boolean.class, int.class, int.class, type, type)).
2766                     invokeExact(0, 0, true, true);
2767             });
2768             checkWMTE(() -> { // index reference class
2769                 boolean r = (boolean) hs.get(am, methodType(boolean.class, boolean[].class, Class.class, type, type)).
2770                     invokeExact(array, Void.class, true, true);
2771             });
2772             // Incorrect arity
2773             checkWMTE(() -> { // 0
2774                 boolean r = (boolean) hs.get(am, methodType(boolean.class)).
2775                     invokeExact();
2776             });
2777             checkWMTE(() -> { // >
2778                 boolean r = (boolean) hs.get(am, methodType(boolean.class, boolean[].class, int.class, type, type, Class.class)).
2779                     invokeExact(array, 0, true, true, Void.class);
2780             });
2781         }
2782 
2783         for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
2784             // Incorrect argument types
2785             checkNPE(() -> { // null receiver
2786                 boolean x = (boolean) hs.get(am, methodType(type, boolean[].class, int.class, type, type)).
2787                     invokeExact((boolean[]) null, 0, true, true);
2788             });
2789             hs.checkWMTEOrCCE(() -> { // array reference class
2790                 boolean x = (boolean) hs.get(am, methodType(type, Class.class, int.class, type, type)).
2791                     invokeExact(Void.class, 0, true, true);
2792             });
2793             checkWMTE(() -> { // expected reference class
2794                 boolean x = (boolean) hs.get(am, methodType(type, boolean[].class, int.class, Class.class, type)).
2795                     invokeExact(array, 0, Void.class, true);
2796             });
2797             checkWMTE(() -> { // actual reference class
2798                 boolean x = (boolean) hs.get(am, methodType(type, boolean[].class, int.class, type, Class.class)).
2799                     invokeExact(array, 0, true, Void.class);
2800             });
2801             checkWMTE(() -> { // array primitive class
2802                 boolean x = (boolean) hs.get(am, methodType(type, int.class, int.class, type, type)).
2803                     invokeExact(0, 0, true, true);
2804             });
2805             checkWMTE(() -> { // index reference class
2806                 boolean x = (boolean) hs.get(am, methodType(type, boolean[].class, Class.class, type, type)).
2807                     invokeExact(array, Void.class, true, true);
2808             });
2809             // Incorrect return type
2810             checkWMTE(() -> { // reference class
2811                 Void r = (Void) hs.get(am, methodType(Void.class, boolean[].class, int.class, type, type)).
2812                     invokeExact(array, 0, true, true);
2813             });
2814             checkWMTE(() -> { // primitive class
2815                 int x = (int) hs.get(am, methodType(int.class, boolean[].class, int.class, type, type)).
2816                     invokeExact(array, 0, true, true);
2817             });
2818             // Incorrect arity
2819             checkWMTE(() -> { // 0
2820                 boolean x = (boolean) hs.get(am, methodType(type)).
2821                     invokeExact();
2822             });
2823             checkWMTE(() -> { // >
2824                 boolean x = (boolean) hs.get(am, methodType(type, boolean[].class, int.class, type, type, Class.class)).
2825                     invokeExact(array, 0, true, true, Void.class);
2826             });
2827         }
2828 
2829         for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
2830             // Incorrect argument types
2831             checkNPE(() -> { // null array
2832                 boolean x = (boolean) hs.get(am, methodType(type, boolean[].class, int.class, type)).
2833                     invokeExact((boolean[]) null, 0, true);
2834             });
2835             hs.checkWMTEOrCCE(() -> { // array reference class
2836                 boolean x = (boolean) hs.get(am, methodType(type, Class.class, int.class, type)).
2837                     invokeExact(Void.class, 0, true);
2838             });
2839             checkWMTE(() -> { // value reference class
2840                 boolean x = (boolean) hs.get(am, methodType(type, boolean[].class, int.class, Class.class)).
2841                     invokeExact(array, 0, Void.class);
2842             });
2843             checkWMTE(() -> { // array primitive class
2844                 boolean x = (boolean) hs.get(am, methodType(type, int.class, int.class, type)).
2845                     invokeExact(0, 0, true);
2846             });
2847             checkWMTE(() -> { // index reference class
2848                 boolean x = (boolean) hs.get(am, methodType(type, boolean[].class, Class.class, type)).
2849                     invokeExact(array, Void.class, true);
2850             });
2851             // Incorrect return type
2852             checkWMTE(() -> { // reference class
2853                 Void r = (Void) hs.get(am, methodType(Void.class, boolean[].class, int.class, type)).
2854                     invokeExact(array, 0, true);
2855             });
2856             checkWMTE(() -> { // primitive class
2857                 int x = (int) hs.get(am, methodType(int.class, boolean[].class, int.class, type)).
2858                     invokeExact(array, 0, true);
2859             });
2860             // Incorrect arity
2861             checkWMTE(() -> { // 0
2862                 boolean x = (boolean) hs.get(am, methodType(type)).
2863                     invokeExact();
2864             });
2865             checkWMTE(() -> { // >
2866                 boolean x = (boolean) hs.get(am, methodType(type, boolean[].class, int.class, type, Class.class)).
2867                     invokeExact(array, 0, true, Void.class);
2868             });
2869         }
2870 
2871 
2872         for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_BITWISE)) {
2873             // Incorrect argument types
2874             checkNPE(() -> { // null array
2875                 boolean x = (boolean) hs.get(am, methodType(type, boolean[].class, int.class, type)).
2876                     invokeExact((boolean[]) null, 0, true);
2877             });
2878             hs.checkWMTEOrCCE(() -> { // array reference class
2879                 boolean x = (boolean) hs.get(am, methodType(type, Class.class, int.class, type)).
2880                     invokeExact(Void.class, 0, true);
2881             });
2882             checkWMTE(() -> { // value reference class
2883                 boolean x = (boolean) hs.get(am, methodType(type, boolean[].class, int.class, Class.class)).
2884                     invokeExact(array, 0, Void.class);
2885             });
2886             checkWMTE(() -> { // array primitive class
2887                 boolean x = (boolean) hs.get(am, methodType(type, int.class, int.class, type)).
2888                     invokeExact(0, 0, true);
2889             });
2890             checkWMTE(() -> { // index reference class
2891                 boolean x = (boolean) hs.get(am, methodType(type, boolean[].class, Class.class, type)).
2892                     invokeExact(array, Void.class, true);
2893             });
2894             // Incorrect return type
2895             checkWMTE(() -> { // reference class
2896                 Void r = (Void) hs.get(am, methodType(Void.class, boolean[].class, int.class, type)).
2897                     invokeExact(array, 0, true);
2898             });
2899             checkWMTE(() -> { // primitive class
2900                 int x = (int) hs.get(am, methodType(int.class, boolean[].class, int.class, type)).
2901                     invokeExact(array, 0, true);
2902             });
2903             // Incorrect arity
2904             checkWMTE(() -> { // 0
2905                 boolean x = (boolean) hs.get(am, methodType(type)).
2906                     invokeExact();
2907             });
2908             checkWMTE(() -> { // >
2909                 boolean x = (boolean) hs.get(am, methodType(type, boolean[].class, int.class, type, Class.class)).
2910                     invokeExact(array, 0, true, Void.class);
2911             });
2912         }
2913     }
2914 }
< prev index next >