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 VarHandleTestMethodTypeByte
28 * @run testng/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=true -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true VarHandleTestMethodTypeByte
29 * @run testng/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=false VarHandleTestMethodTypeByte
30 * @run testng/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true VarHandleTestMethodTypeByte
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 VarHandleTestMethodTypeByte extends VarHandleBaseTest {
48 static final byte static_final_v = (byte)0x01;
49
50 static byte static_v = (byte)0x01;
51
52 final byte final_v = (byte)0x01;
53
54 byte v = (byte)0x01;
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 VarHandleTestMethodTypeByte.class, "final_v", byte.class);
70
71 vhField = MethodHandles.lookup().findVarHandle(
72 VarHandleTestMethodTypeByte.class, "v", byte.class);
73
74 vhStaticFinalField = MethodHandles.lookup().findStaticVarHandle(
75 VarHandleTestMethodTypeByte.class, "static_final_v", byte.class);
76
77 vhStaticField = MethodHandles.lookup().findStaticVarHandle(
78 VarHandleTestMethodTypeByte.class, "static_v", byte.class);
79
80 vhArray = MethodHandles.arrayElementVarHandle(byte[].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, VarHandleTestMethodTypeByte::testStaticFieldWrongMethodType,
93 false));
94
95 cases.add(new VarHandleAccessTestCase("Array",
96 vhArray, VarHandleTestMethodTypeByte::testArrayWrongMethodType,
97 false));
98
986 // Incorrect return type
987 checkWMTE(() -> { // reference class
988 Void r = (Void) vh.getAndBitwiseXor(recv, (byte)0x01);
989 });
990 checkWMTE(() -> { // primitive class
991 boolean x = (boolean) vh.getAndBitwiseXor(recv, (byte)0x01);
992 });
993 // Incorrect arity
994 checkWMTE(() -> { // 0
995 byte x = (byte) vh.getAndBitwiseXor();
996 });
997 checkWMTE(() -> { // >
998 byte x = (byte) vh.getAndBitwiseXor(recv, (byte)0x01, Void.class);
999 });
1000 }
1001
1002 static void testInstanceFieldWrongMethodType(VarHandleTestMethodTypeByte recv, Handles hs) throws Throwable {
1003 for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET)) {
1004 // Incorrect argument types
1005 checkNPE(() -> { // null receiver
1006 byte x = (byte) hs.get(am, methodType(byte.class, VarHandleTestMethodTypeByte.class)).
1007 invokeExact((VarHandleTestMethodTypeByte) null);
1008 });
1009 hs.checkWMTEOrCCE(() -> { // receiver reference class
1010 byte x = (byte) hs.get(am, methodType(byte.class, Class.class)).
1011 invokeExact(Void.class);
1012 });
1013 checkWMTE(() -> { // receiver primitive class
1014 byte x = (byte) hs.get(am, methodType(byte.class, int.class)).
1015 invokeExact(0);
1016 });
1017 // Incorrect return type
1018 checkWMTE(() -> { // reference class
1019 Void x = (Void) hs.get(am, methodType(Void.class, VarHandleTestMethodTypeByte.class)).
1020 invokeExact(recv);
1021 });
1022 checkWMTE(() -> { // primitive class
1023 boolean x = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeByte.class)).
1024 invokeExact(recv);
1025 });
1026 // Incorrect arity
1027 checkWMTE(() -> { // 0
1028 byte x = (byte) hs.get(am, methodType(byte.class)).
1029 invokeExact();
1030 });
1031 checkWMTE(() -> { // >
1032 byte x = (byte) hs.get(am, methodType(byte.class, VarHandleTestMethodTypeByte.class, Class.class)).
1033 invokeExact(recv, Void.class);
1034 });
1035 }
1036
1037 for (TestAccessMode am : testAccessModesOfType(TestAccessType.SET)) {
1038 // Incorrect argument types
1039 checkNPE(() -> { // null receiver
1040 hs.get(am, methodType(void.class, VarHandleTestMethodTypeByte.class, byte.class)).
1041 invokeExact((VarHandleTestMethodTypeByte) null, (byte)0x01);
1042 });
1043 hs.checkWMTEOrCCE(() -> { // receiver reference class
1044 hs.get(am, methodType(void.class, Class.class, byte.class)).
1045 invokeExact(Void.class, (byte)0x01);
1046 });
1047 checkWMTE(() -> { // value reference class
1048 hs.get(am, methodType(void.class, VarHandleTestMethodTypeByte.class, Class.class)).
1049 invokeExact(recv, Void.class);
1050 });
1051 checkWMTE(() -> { // receiver primitive class
1052 hs.get(am, methodType(void.class, int.class, byte.class)).
1053 invokeExact(0, (byte)0x01);
1054 });
1055 // Incorrect arity
1056 checkWMTE(() -> { // 0
1057 hs.get(am, methodType(void.class)).
1058 invokeExact();
1059 });
1060 checkWMTE(() -> { // >
1061 hs.get(am, methodType(void.class, VarHandleTestMethodTypeByte.class, byte.class, Class.class)).
1062 invokeExact(recv, (byte)0x01, Void.class);
1063 });
1064 }
1065
1066 for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
1067 // Incorrect argument types
1068 checkNPE(() -> { // null receiver
1069 boolean r = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeByte.class, byte.class, byte.class)).
1070 invokeExact((VarHandleTestMethodTypeByte) null, (byte)0x01, (byte)0x01);
1071 });
1072 hs.checkWMTEOrCCE(() -> { // receiver reference class
1073 boolean r = (boolean) hs.get(am, methodType(boolean.class, Class.class, byte.class, byte.class)).
1074 invokeExact(Void.class, (byte)0x01, (byte)0x01);
1075 });
1076 checkWMTE(() -> { // expected reference class
1077 boolean r = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeByte.class, Class.class, byte.class)).
1078 invokeExact(recv, Void.class, (byte)0x01);
1079 });
1080 checkWMTE(() -> { // actual reference class
1081 boolean r = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeByte.class, byte.class, Class.class)).
1082 invokeExact(recv, (byte)0x01, Void.class);
1083 });
1084 checkWMTE(() -> { // receiver primitive class
1085 boolean r = (boolean) hs.get(am, methodType(boolean.class, int.class , byte.class, byte.class)).
1086 invokeExact(0, (byte)0x01, (byte)0x01);
1087 });
1088 // Incorrect arity
1089 checkWMTE(() -> { // 0
1090 boolean r = (boolean) hs.get(am, methodType(boolean.class)).
1091 invokeExact();
1092 });
1093 checkWMTE(() -> { // >
1094 boolean r = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeByte.class, byte.class, byte.class, Class.class)).
1095 invokeExact(recv, (byte)0x01, (byte)0x01, Void.class);
1096 });
1097 }
1098
1099 for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
1100 checkNPE(() -> { // null receiver
1101 byte x = (byte) hs.get(am, methodType(byte.class, VarHandleTestMethodTypeByte.class, byte.class, byte.class)).
1102 invokeExact((VarHandleTestMethodTypeByte) null, (byte)0x01, (byte)0x01);
1103 });
1104 hs.checkWMTEOrCCE(() -> { // receiver reference class
1105 byte x = (byte) hs.get(am, methodType(byte.class, Class.class, byte.class, byte.class)).
1106 invokeExact(Void.class, (byte)0x01, (byte)0x01);
1107 });
1108 checkWMTE(() -> { // expected reference class
1109 byte x = (byte) hs.get(am, methodType(byte.class, VarHandleTestMethodTypeByte.class, Class.class, byte.class)).
1110 invokeExact(recv, Void.class, (byte)0x01);
1111 });
1112 checkWMTE(() -> { // actual reference class
1113 byte x = (byte) hs.get(am, methodType(byte.class, VarHandleTestMethodTypeByte.class, byte.class, Class.class)).
1114 invokeExact(recv, (byte)0x01, Void.class);
1115 });
1116 checkWMTE(() -> { // reciever primitive class
1117 byte x = (byte) hs.get(am, methodType(byte.class, int.class , byte.class, byte.class)).
1118 invokeExact(0, (byte)0x01, (byte)0x01);
1119 });
1120 // Incorrect return type
1121 checkWMTE(() -> { // reference class
1122 Void r = (Void) hs.get(am, methodType(Void.class, VarHandleTestMethodTypeByte.class , byte.class, byte.class)).
1123 invokeExact(recv, (byte)0x01, (byte)0x01);
1124 });
1125 checkWMTE(() -> { // primitive class
1126 boolean x = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeByte.class , byte.class, byte.class)).
1127 invokeExact(recv, (byte)0x01, (byte)0x01);
1128 });
1129 // Incorrect arity
1130 checkWMTE(() -> { // 0
1131 byte x = (byte) hs.get(am, methodType(byte.class)).
1132 invokeExact();
1133 });
1134 checkWMTE(() -> { // >
1135 byte x = (byte) hs.get(am, methodType(byte.class, VarHandleTestMethodTypeByte.class, byte.class, byte.class, Class.class)).
1136 invokeExact(recv, (byte)0x01, (byte)0x01, Void.class);
1137 });
1138 }
1139
1140 for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
1141 checkNPE(() -> { // null receiver
1142 byte x = (byte) hs.get(am, methodType(byte.class, VarHandleTestMethodTypeByte.class, byte.class)).
1143 invokeExact((VarHandleTestMethodTypeByte) null, (byte)0x01);
1144 });
1145 hs.checkWMTEOrCCE(() -> { // receiver reference class
1146 byte x = (byte) hs.get(am, methodType(byte.class, Class.class, byte.class)).
1147 invokeExact(Void.class, (byte)0x01);
1148 });
1149 checkWMTE(() -> { // value reference class
1150 byte x = (byte) hs.get(am, methodType(byte.class, VarHandleTestMethodTypeByte.class, Class.class)).
1151 invokeExact(recv, Void.class);
1152 });
1153 checkWMTE(() -> { // reciever primitive class
1154 byte x = (byte) hs.get(am, methodType(byte.class, int.class, byte.class)).
1155 invokeExact(0, (byte)0x01);
1156 });
1157 // Incorrect return type
1158 checkWMTE(() -> { // reference class
1159 Void r = (Void) hs.get(am, methodType(Void.class, VarHandleTestMethodTypeByte.class, byte.class)).
1160 invokeExact(recv, (byte)0x01);
1161 });
1162 checkWMTE(() -> { // primitive class
1163 boolean x = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeByte.class, byte.class)).
1164 invokeExact(recv, (byte)0x01);
1165 });
1166 // Incorrect arity
1167 checkWMTE(() -> { // 0
1168 byte x = (byte) hs.get(am, methodType(byte.class)).
1169 invokeExact();
1170 });
1171 checkWMTE(() -> { // >
1172 byte x = (byte) hs.get(am, methodType(byte.class, VarHandleTestMethodTypeByte.class, byte.class)).
1173 invokeExact(recv, (byte)0x01, Void.class);
1174 });
1175 }
1176
1177 for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) {
1178 checkNPE(() -> { // null receiver
1179 byte x = (byte) hs.get(am, methodType(byte.class, VarHandleTestMethodTypeByte.class, byte.class)).
1180 invokeExact((VarHandleTestMethodTypeByte) null, (byte)0x01);
1181 });
1182 hs.checkWMTEOrCCE(() -> { // receiver reference class
1183 byte x = (byte) hs.get(am, methodType(byte.class, Class.class, byte.class)).
1184 invokeExact(Void.class, (byte)0x01);
1185 });
1186 checkWMTE(() -> { // value reference class
1187 byte x = (byte) hs.get(am, methodType(byte.class, VarHandleTestMethodTypeByte.class, Class.class)).
1188 invokeExact(recv, Void.class);
1189 });
1190 checkWMTE(() -> { // reciever primitive class
1191 byte x = (byte) hs.get(am, methodType(byte.class, int.class, byte.class)).
1192 invokeExact(0, (byte)0x01);
1193 });
1194 // Incorrect return type
1195 checkWMTE(() -> { // reference class
1196 Void r = (Void) hs.get(am, methodType(Void.class, VarHandleTestMethodTypeByte.class, byte.class)).
1197 invokeExact(recv, (byte)0x01);
1198 });
1199 checkWMTE(() -> { // primitive class
1200 boolean x = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeByte.class, byte.class)).
1201 invokeExact(recv, (byte)0x01);
1202 });
1203 // Incorrect arity
1204 checkWMTE(() -> { // 0
1205 byte x = (byte) hs.get(am, methodType(byte.class)).
1206 invokeExact();
1207 });
1208 checkWMTE(() -> { // >
1209 byte x = (byte) hs.get(am, methodType(byte.class, VarHandleTestMethodTypeByte.class, byte.class)).
1210 invokeExact(recv, (byte)0x01, Void.class);
1211 });
1212 }
1213
1214 for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_BITWISE)) {
1215 checkNPE(() -> { // null receiver
1216 byte x = (byte) hs.get(am, methodType(byte.class, VarHandleTestMethodTypeByte.class, byte.class)).
1217 invokeExact((VarHandleTestMethodTypeByte) null, (byte)0x01);
1218 });
1219 hs.checkWMTEOrCCE(() -> { // receiver reference class
1220 byte x = (byte) hs.get(am, methodType(byte.class, Class.class, byte.class)).
1221 invokeExact(Void.class, (byte)0x01);
1222 });
1223 checkWMTE(() -> { // value reference class
1224 byte x = (byte) hs.get(am, methodType(byte.class, VarHandleTestMethodTypeByte.class, Class.class)).
1225 invokeExact(recv, Void.class);
1226 });
1227 checkWMTE(() -> { // reciever primitive class
1228 byte x = (byte) hs.get(am, methodType(byte.class, int.class, byte.class)).
1229 invokeExact(0, (byte)0x01);
1230 });
1231 // Incorrect return type
1232 checkWMTE(() -> { // reference class
1233 Void r = (Void) hs.get(am, methodType(Void.class, VarHandleTestMethodTypeByte.class, byte.class)).
1234 invokeExact(recv, (byte)0x01);
1235 });
1236 checkWMTE(() -> { // primitive class
1237 boolean x = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeByte.class, byte.class)).
1238 invokeExact(recv, (byte)0x01);
1239 });
1240 // Incorrect arity
1241 checkWMTE(() -> { // 0
1242 byte x = (byte) hs.get(am, methodType(byte.class)).
1243 invokeExact();
1244 });
1245 checkWMTE(() -> { // >
1246 byte x = (byte) hs.get(am, methodType(byte.class, VarHandleTestMethodTypeByte.class, byte.class)).
1247 invokeExact(recv, (byte)0x01, Void.class);
1248 });
1249 }
1250 }
1251
1252
1253 static void testStaticFieldWrongMethodType(VarHandle vh) throws Throwable {
1254 // Get
1255 // Incorrect return type
1256 checkWMTE(() -> { // reference class
1257 Void x = (Void) vh.get();
1258 });
1259 checkWMTE(() -> { // primitive class
1260 boolean x = (boolean) vh.get();
1261 });
1262 // Incorrect arity
1263 checkWMTE(() -> { // >
1264 byte x = (byte) vh.get(Void.class);
1265 });
1266
1844 invokeExact();
1845 });
1846 // Incorrect arity
1847 checkWMTE(() -> { // >
1848 byte x = (byte) hs.get(am, methodType(Class.class)).
1849 invokeExact(Void.class);
1850 });
1851 }
1852
1853 for (TestAccessMode am : testAccessModesOfType(TestAccessType.SET)) {
1854 checkWMTE(() -> { // value reference class
1855 hs.get(am, methodType(void.class, Class.class)).
1856 invokeExact(Void.class);
1857 });
1858 // Incorrect arity
1859 checkWMTE(() -> { // 0
1860 hs.get(am, methodType(void.class)).
1861 invokeExact();
1862 });
1863 checkWMTE(() -> { // >
1864 hs.get(am, methodType(void.class, byte.class, Class.class)).
1865 invokeExact((byte)0x01, Void.class);
1866 });
1867 }
1868 for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
1869 // Incorrect argument types
1870 checkWMTE(() -> { // expected reference class
1871 boolean r = (boolean) hs.get(am, methodType(boolean.class, Class.class, byte.class)).
1872 invokeExact(Void.class, (byte)0x01);
1873 });
1874 checkWMTE(() -> { // actual reference class
1875 boolean r = (boolean) hs.get(am, methodType(boolean.class, byte.class, Class.class)).
1876 invokeExact((byte)0x01, Void.class);
1877 });
1878 // Incorrect arity
1879 checkWMTE(() -> { // 0
1880 boolean r = (boolean) hs.get(am, methodType(boolean.class)).
1881 invokeExact();
1882 });
1883 checkWMTE(() -> { // >
1884 boolean r = (boolean) hs.get(am, methodType(boolean.class, byte.class, byte.class, Class.class)).
1885 invokeExact((byte)0x01, (byte)0x01, Void.class);
1886 });
1887 }
1888
1889 for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
1890 // Incorrect argument types
1891 checkWMTE(() -> { // expected reference class
1892 byte x = (byte) hs.get(am, methodType(byte.class, Class.class, byte.class)).
1893 invokeExact(Void.class, (byte)0x01);
1894 });
1895 checkWMTE(() -> { // actual reference class
1896 byte x = (byte) hs.get(am, methodType(byte.class, byte.class, Class.class)).
1897 invokeExact((byte)0x01, Void.class);
1898 });
1899 // Incorrect return type
1900 checkWMTE(() -> { // reference class
1901 Void r = (Void) hs.get(am, methodType(Void.class, byte.class, byte.class)).
1902 invokeExact((byte)0x01, (byte)0x01);
1903 });
1904 checkWMTE(() -> { // primitive class
1905 boolean x = (boolean) hs.get(am, methodType(boolean.class, byte.class, byte.class)).
1906 invokeExact((byte)0x01, (byte)0x01);
1907 });
1908 // Incorrect arity
1909 checkWMTE(() -> { // 0
1910 byte x = (byte) hs.get(am, methodType(byte.class)).
1911 invokeExact();
1912 });
1913 checkWMTE(() -> { // >
1914 byte x = (byte) hs.get(am, methodType(byte.class, byte.class, byte.class, Class.class)).
1915 invokeExact((byte)0x01, (byte)0x01, Void.class);
1916 });
1917 }
1918
1919 for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
1920 // Incorrect argument types
1921 checkWMTE(() -> { // value reference class
1922 byte x = (byte) hs.get(am, methodType(byte.class, Class.class)).
1923 invokeExact(Void.class);
1924 });
1925 // Incorrect return type
1926 checkWMTE(() -> { // reference class
1927 Void r = (Void) hs.get(am, methodType(Void.class, byte.class)).
1928 invokeExact((byte)0x01);
1929 });
1930 checkWMTE(() -> { // primitive class
1931 boolean x = (boolean) hs.get(am, methodType(boolean.class, byte.class)).
1932 invokeExact((byte)0x01);
1933 });
1934 // Incorrect arity
1935 checkWMTE(() -> { // 0
1936 byte x = (byte) hs.get(am, methodType(byte.class)).
1937 invokeExact();
1938 });
1939 checkWMTE(() -> { // >
1940 byte x = (byte) hs.get(am, methodType(byte.class, byte.class, Class.class)).
1941 invokeExact((byte)0x01, Void.class);
1942 });
1943 }
1944
1945 for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) {
1946 // Incorrect argument types
1947 checkWMTE(() -> { // value reference class
1948 byte x = (byte) hs.get(am, methodType(byte.class, Class.class)).
1949 invokeExact(Void.class);
1950 });
1951 // Incorrect return type
1952 checkWMTE(() -> { // reference class
1953 Void r = (Void) hs.get(am, methodType(Void.class, byte.class)).
1954 invokeExact((byte)0x01);
1955 });
1956 checkWMTE(() -> { // primitive class
1957 boolean x = (boolean) hs.get(am, methodType(boolean.class, byte.class)).
1958 invokeExact((byte)0x01);
1959 });
1960 // Incorrect arity
1961 checkWMTE(() -> { // 0
1962 byte x = (byte) hs.get(am, methodType(byte.class)).
1963 invokeExact();
1964 });
1965 checkWMTE(() -> { // >
1966 byte x = (byte) hs.get(am, methodType(byte.class, byte.class, Class.class)).
1967 invokeExact((byte)0x01, Void.class);
1968 });
1969 }
1970
1971 for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_BITWISE)) {
1972 // Incorrect argument types
1973 checkWMTE(() -> { // value reference class
1974 byte x = (byte) hs.get(am, methodType(byte.class, Class.class)).
1975 invokeExact(Void.class);
1976 });
1977 // Incorrect return type
1978 checkWMTE(() -> { // reference class
1979 Void r = (Void) hs.get(am, methodType(Void.class, byte.class)).
1980 invokeExact((byte)0x01);
1981 });
1982 checkWMTE(() -> { // primitive class
1983 boolean x = (boolean) hs.get(am, methodType(boolean.class, byte.class)).
1984 invokeExact((byte)0x01);
1985 });
1986 // Incorrect arity
1987 checkWMTE(() -> { // 0
1988 byte x = (byte) hs.get(am, methodType(byte.class)).
1989 invokeExact();
1990 });
1991 checkWMTE(() -> { // >
1992 byte x = (byte) hs.get(am, methodType(byte.class, byte.class, Class.class)).
1993 invokeExact((byte)0x01, Void.class);
1994 });
1995 }
1996 }
1997
1998
1999 static void testArrayWrongMethodType(VarHandle vh) throws Throwable {
2000 byte[] array = new byte[10];
2001 Arrays.fill(array, (byte)0x01);
2002
2003 // Get
2004 // Incorrect argument types
2005 checkNPE(() -> { // null array
2006 byte x = (byte) vh.get(null, 0);
2007 });
2008 checkCCE(() -> { // array reference class
2009 byte x = (byte) vh.get(Void.class, 0);
2010 });
2011 checkWMTE(() -> { // array primitive class
2012 byte x = (byte) vh.get(0, 0);
2960 });
2961 checkWMTE(() -> { // primitive class
2962 boolean x = (boolean) vh.getAndBitwiseXorRelease(array, 0, (byte)0x01);
2963 });
2964 // Incorrect arity
2965 checkWMTE(() -> { // 0
2966 byte x = (byte) vh.getAndBitwiseXorRelease();
2967 });
2968 checkWMTE(() -> { // >
2969 byte x = (byte) vh.getAndBitwiseXorRelease(array, 0, (byte)0x01, Void.class);
2970 });
2971 }
2972
2973 static void testArrayWrongMethodType(Handles hs) throws Throwable {
2974 byte[] array = new byte[10];
2975 Arrays.fill(array, (byte)0x01);
2976
2977 for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET)) {
2978 // Incorrect argument types
2979 checkNPE(() -> { // null array
2980 byte x = (byte) hs.get(am, methodType(byte.class, byte[].class, int.class)).
2981 invokeExact((byte[]) null, 0);
2982 });
2983 hs.checkWMTEOrCCE(() -> { // array reference class
2984 byte x = (byte) hs.get(am, methodType(byte.class, Class.class, int.class)).
2985 invokeExact(Void.class, 0);
2986 });
2987 checkWMTE(() -> { // array primitive class
2988 byte x = (byte) hs.get(am, methodType(byte.class, int.class, int.class)).
2989 invokeExact(0, 0);
2990 });
2991 checkWMTE(() -> { // index reference class
2992 byte x = (byte) hs.get(am, methodType(byte.class, byte[].class, Class.class)).
2993 invokeExact(array, Void.class);
2994 });
2995 // Incorrect return type
2996 checkWMTE(() -> { // reference class
2997 Void x = (Void) hs.get(am, methodType(Void.class, byte[].class, int.class)).
2998 invokeExact(array, 0);
2999 });
3000 checkWMTE(() -> { // primitive class
3001 boolean x = (boolean) hs.get(am, methodType(boolean.class, byte[].class, int.class)).
3002 invokeExact(array, 0);
3003 });
3004 // Incorrect arity
3005 checkWMTE(() -> { // 0
3006 byte x = (byte) hs.get(am, methodType(byte.class)).
3007 invokeExact();
3008 });
3009 checkWMTE(() -> { // >
3010 byte x = (byte) hs.get(am, methodType(byte.class, byte[].class, int.class, Class.class)).
3011 invokeExact(array, 0, Void.class);
3012 });
3013 }
3014
3015 for (TestAccessMode am : testAccessModesOfType(TestAccessType.SET)) {
3016 // Incorrect argument types
3017 checkNPE(() -> { // null array
3018 hs.get(am, methodType(void.class, byte[].class, int.class, byte.class)).
3019 invokeExact((byte[]) null, 0, (byte)0x01);
3020 });
3021 hs.checkWMTEOrCCE(() -> { // array reference class
3022 hs.get(am, methodType(void.class, Class.class, int.class, byte.class)).
3023 invokeExact(Void.class, 0, (byte)0x01);
3024 });
3025 checkWMTE(() -> { // value reference class
3026 hs.get(am, methodType(void.class, byte[].class, int.class, Class.class)).
3027 invokeExact(array, 0, Void.class);
3028 });
3029 checkWMTE(() -> { // receiver primitive class
3030 hs.get(am, methodType(void.class, int.class, int.class, byte.class)).
3031 invokeExact(0, 0, (byte)0x01);
3032 });
3033 checkWMTE(() -> { // index reference class
3034 hs.get(am, methodType(void.class, byte[].class, Class.class, byte.class)).
3035 invokeExact(array, Void.class, (byte)0x01);
3036 });
3037 // Incorrect arity
3038 checkWMTE(() -> { // 0
3039 hs.get(am, methodType(void.class)).
3040 invokeExact();
3041 });
3042 checkWMTE(() -> { // >
3043 hs.get(am, methodType(void.class, byte[].class, int.class, Class.class)).
3044 invokeExact(array, 0, (byte)0x01, Void.class);
3045 });
3046 }
3047 for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
3048 // Incorrect argument types
3049 checkNPE(() -> { // null receiver
3050 boolean r = (boolean) hs.get(am, methodType(boolean.class, byte[].class, int.class, byte.class, byte.class)).
3051 invokeExact((byte[]) null, 0, (byte)0x01, (byte)0x01);
3052 });
3053 hs.checkWMTEOrCCE(() -> { // receiver reference class
3054 boolean r = (boolean) hs.get(am, methodType(boolean.class, Class.class, int.class, byte.class, byte.class)).
3055 invokeExact(Void.class, 0, (byte)0x01, (byte)0x01);
3056 });
3057 checkWMTE(() -> { // expected reference class
3058 boolean r = (boolean) hs.get(am, methodType(boolean.class, byte[].class, int.class, Class.class, byte.class)).
3059 invokeExact(array, 0, Void.class, (byte)0x01);
3060 });
3061 checkWMTE(() -> { // actual reference class
3062 boolean r = (boolean) hs.get(am, methodType(boolean.class, byte[].class, int.class, byte.class, Class.class)).
3063 invokeExact(array, 0, (byte)0x01, Void.class);
3064 });
3065 checkWMTE(() -> { // receiver primitive class
3066 boolean r = (boolean) hs.get(am, methodType(boolean.class, int.class, int.class, byte.class, byte.class)).
3067 invokeExact(0, 0, (byte)0x01, (byte)0x01);
3068 });
3069 checkWMTE(() -> { // index reference class
3070 boolean r = (boolean) hs.get(am, methodType(boolean.class, byte[].class, Class.class, byte.class, byte.class)).
3071 invokeExact(array, Void.class, (byte)0x01, (byte)0x01);
3072 });
3073 // Incorrect arity
3074 checkWMTE(() -> { // 0
3075 boolean r = (boolean) hs.get(am, methodType(boolean.class)).
3076 invokeExact();
3077 });
3078 checkWMTE(() -> { // >
3079 boolean r = (boolean) hs.get(am, methodType(boolean.class, byte[].class, int.class, byte.class, byte.class, Class.class)).
3080 invokeExact(array, 0, (byte)0x01, (byte)0x01, Void.class);
3081 });
3082 }
3083
3084 for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
3085 // Incorrect argument types
3086 checkNPE(() -> { // null receiver
3087 byte x = (byte) hs.get(am, methodType(byte.class, byte[].class, int.class, byte.class, byte.class)).
3088 invokeExact((byte[]) null, 0, (byte)0x01, (byte)0x01);
3089 });
3090 hs.checkWMTEOrCCE(() -> { // array reference class
3091 byte x = (byte) hs.get(am, methodType(byte.class, Class.class, int.class, byte.class, byte.class)).
3092 invokeExact(Void.class, 0, (byte)0x01, (byte)0x01);
3093 });
3094 checkWMTE(() -> { // expected reference class
3095 byte x = (byte) hs.get(am, methodType(byte.class, byte[].class, int.class, Class.class, byte.class)).
3096 invokeExact(array, 0, Void.class, (byte)0x01);
3097 });
3098 checkWMTE(() -> { // actual reference class
3099 byte x = (byte) hs.get(am, methodType(byte.class, byte[].class, int.class, byte.class, Class.class)).
3100 invokeExact(array, 0, (byte)0x01, Void.class);
3101 });
3102 checkWMTE(() -> { // array primitive class
3103 byte x = (byte) hs.get(am, methodType(byte.class, int.class, int.class, byte.class, byte.class)).
3104 invokeExact(0, 0, (byte)0x01, (byte)0x01);
3105 });
3106 checkWMTE(() -> { // index reference class
3107 byte x = (byte) hs.get(am, methodType(byte.class, byte[].class, Class.class, byte.class, byte.class)).
3108 invokeExact(array, Void.class, (byte)0x01, (byte)0x01);
3109 });
3110 // Incorrect return type
3111 checkWMTE(() -> { // reference class
3112 Void r = (Void) hs.get(am, methodType(Void.class, byte[].class, int.class, byte.class, byte.class)).
3113 invokeExact(array, 0, (byte)0x01, (byte)0x01);
3114 });
3115 checkWMTE(() -> { // primitive class
3116 boolean x = (boolean) hs.get(am, methodType(boolean.class, byte[].class, int.class, byte.class, byte.class)).
3117 invokeExact(array, 0, (byte)0x01, (byte)0x01);
3118 });
3119 // Incorrect arity
3120 checkWMTE(() -> { // 0
3121 byte x = (byte) hs.get(am, methodType(byte.class)).
3122 invokeExact();
3123 });
3124 checkWMTE(() -> { // >
3125 byte x = (byte) hs.get(am, methodType(byte.class, byte[].class, int.class, byte.class, byte.class, Class.class)).
3126 invokeExact(array, 0, (byte)0x01, (byte)0x01, Void.class);
3127 });
3128 }
3129
3130 for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
3131 // Incorrect argument types
3132 checkNPE(() -> { // null array
3133 byte x = (byte) hs.get(am, methodType(byte.class, byte[].class, int.class, byte.class)).
3134 invokeExact((byte[]) null, 0, (byte)0x01);
3135 });
3136 hs.checkWMTEOrCCE(() -> { // array reference class
3137 byte x = (byte) hs.get(am, methodType(byte.class, Class.class, int.class, byte.class)).
3138 invokeExact(Void.class, 0, (byte)0x01);
3139 });
3140 checkWMTE(() -> { // value reference class
3141 byte x = (byte) hs.get(am, methodType(byte.class, byte[].class, int.class, Class.class)).
3142 invokeExact(array, 0, Void.class);
3143 });
3144 checkWMTE(() -> { // array primitive class
3145 byte x = (byte) hs.get(am, methodType(byte.class, int.class, int.class, byte.class)).
3146 invokeExact(0, 0, (byte)0x01);
3147 });
3148 checkWMTE(() -> { // index reference class
3149 byte x = (byte) hs.get(am, methodType(byte.class, byte[].class, Class.class, byte.class)).
3150 invokeExact(array, Void.class, (byte)0x01);
3151 });
3152 // Incorrect return type
3153 checkWMTE(() -> { // reference class
3154 Void r = (Void) hs.get(am, methodType(Void.class, byte[].class, int.class, byte.class)).
3155 invokeExact(array, 0, (byte)0x01);
3156 });
3157 checkWMTE(() -> { // primitive class
3158 boolean x = (boolean) hs.get(am, methodType(boolean.class, byte[].class, int.class, byte.class)).
3159 invokeExact(array, 0, (byte)0x01);
3160 });
3161 // Incorrect arity
3162 checkWMTE(() -> { // 0
3163 byte x = (byte) hs.get(am, methodType(byte.class)).
3164 invokeExact();
3165 });
3166 checkWMTE(() -> { // >
3167 byte x = (byte) hs.get(am, methodType(byte.class, byte[].class, int.class, byte.class, Class.class)).
3168 invokeExact(array, 0, (byte)0x01, Void.class);
3169 });
3170 }
3171
3172 for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) {
3173 // Incorrect argument types
3174 checkNPE(() -> { // null array
3175 byte x = (byte) hs.get(am, methodType(byte.class, byte[].class, int.class, byte.class)).
3176 invokeExact((byte[]) null, 0, (byte)0x01);
3177 });
3178 hs.checkWMTEOrCCE(() -> { // array reference class
3179 byte x = (byte) hs.get(am, methodType(byte.class, Class.class, int.class, byte.class)).
3180 invokeExact(Void.class, 0, (byte)0x01);
3181 });
3182 checkWMTE(() -> { // value reference class
3183 byte x = (byte) hs.get(am, methodType(byte.class, byte[].class, int.class, Class.class)).
3184 invokeExact(array, 0, Void.class);
3185 });
3186 checkWMTE(() -> { // array primitive class
3187 byte x = (byte) hs.get(am, methodType(byte.class, int.class, int.class, byte.class)).
3188 invokeExact(0, 0, (byte)0x01);
3189 });
3190 checkWMTE(() -> { // index reference class
3191 byte x = (byte) hs.get(am, methodType(byte.class, byte[].class, Class.class, byte.class)).
3192 invokeExact(array, Void.class, (byte)0x01);
3193 });
3194 // Incorrect return type
3195 checkWMTE(() -> { // reference class
3196 Void r = (Void) hs.get(am, methodType(Void.class, byte[].class, int.class, byte.class)).
3197 invokeExact(array, 0, (byte)0x01);
3198 });
3199 checkWMTE(() -> { // primitive class
3200 boolean x = (boolean) hs.get(am, methodType(boolean.class, byte[].class, int.class, byte.class)).
3201 invokeExact(array, 0, (byte)0x01);
3202 });
3203 // Incorrect arity
3204 checkWMTE(() -> { // 0
3205 byte x = (byte) hs.get(am, methodType(byte.class)).
3206 invokeExact();
3207 });
3208 checkWMTE(() -> { // >
3209 byte x = (byte) hs.get(am, methodType(byte.class, byte[].class, int.class, byte.class, Class.class)).
3210 invokeExact(array, 0, (byte)0x01, Void.class);
3211 });
3212 }
3213
3214 for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_BITWISE)) {
3215 // Incorrect argument types
3216 checkNPE(() -> { // null array
3217 byte x = (byte) hs.get(am, methodType(byte.class, byte[].class, int.class, byte.class)).
3218 invokeExact((byte[]) null, 0, (byte)0x01);
3219 });
3220 hs.checkWMTEOrCCE(() -> { // array reference class
3221 byte x = (byte) hs.get(am, methodType(byte.class, Class.class, int.class, byte.class)).
3222 invokeExact(Void.class, 0, (byte)0x01);
3223 });
3224 checkWMTE(() -> { // value reference class
3225 byte x = (byte) hs.get(am, methodType(byte.class, byte[].class, int.class, Class.class)).
3226 invokeExact(array, 0, Void.class);
3227 });
3228 checkWMTE(() -> { // array primitive class
3229 byte x = (byte) hs.get(am, methodType(byte.class, int.class, int.class, byte.class)).
3230 invokeExact(0, 0, (byte)0x01);
3231 });
3232 checkWMTE(() -> { // index reference class
3233 byte x = (byte) hs.get(am, methodType(byte.class, byte[].class, Class.class, byte.class)).
3234 invokeExact(array, Void.class, (byte)0x01);
3235 });
3236 // Incorrect return type
3237 checkWMTE(() -> { // reference class
3238 Void r = (Void) hs.get(am, methodType(Void.class, byte[].class, int.class, byte.class)).
3239 invokeExact(array, 0, (byte)0x01);
3240 });
3241 checkWMTE(() -> { // primitive class
3242 boolean x = (boolean) hs.get(am, methodType(boolean.class, byte[].class, int.class, byte.class)).
3243 invokeExact(array, 0, (byte)0x01);
3244 });
3245 // Incorrect arity
3246 checkWMTE(() -> { // 0
3247 byte x = (byte) hs.get(am, methodType(byte.class)).
3248 invokeExact();
3249 });
3250 checkWMTE(() -> { // >
3251 byte x = (byte) hs.get(am, methodType(byte.class, byte[].class, int.class, byte.class, Class.class)).
3252 invokeExact(array, 0, (byte)0x01, Void.class);
3253 });
3254 }
3255 }
3256 }
|
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 VarHandleTestMethodTypeByte
30 * @run testng/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=true -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true VarHandleTestMethodTypeByte
31 * @run testng/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=false VarHandleTestMethodTypeByte
32 * @run testng/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true VarHandleTestMethodTypeByte
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 VarHandleTestMethodTypeByte extends VarHandleBaseTest {
50 static final Class<?> type = byte.class;
51
52 static final byte static_final_v = (byte)0x01;
53
54 static byte static_v = (byte)0x01;
55
56 final byte final_v = (byte)0x01;
57
58 byte v = (byte)0x01;
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 VarHandleTestMethodTypeByte.class, "final_v", type);
74
75 vhField = MethodHandles.lookup().findVarHandle(
76 VarHandleTestMethodTypeByte.class, "v", type);
77
78 vhStaticFinalField = MethodHandles.lookup().findStaticVarHandle(
79 VarHandleTestMethodTypeByte.class, "static_final_v", type);
80
81 vhStaticField = MethodHandles.lookup().findStaticVarHandle(
82 VarHandleTestMethodTypeByte.class, "static_v", type);
83
84 vhArray = MethodHandles.arrayElementVarHandle(byte[].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, VarHandleTestMethodTypeByte::testStaticFieldWrongMethodType,
97 false));
98
99 cases.add(new VarHandleAccessTestCase("Array",
100 vhArray, VarHandleTestMethodTypeByte::testArrayWrongMethodType,
101 false));
102
990 // Incorrect return type
991 checkWMTE(() -> { // reference class
992 Void r = (Void) vh.getAndBitwiseXor(recv, (byte)0x01);
993 });
994 checkWMTE(() -> { // primitive class
995 boolean x = (boolean) vh.getAndBitwiseXor(recv, (byte)0x01);
996 });
997 // Incorrect arity
998 checkWMTE(() -> { // 0
999 byte x = (byte) vh.getAndBitwiseXor();
1000 });
1001 checkWMTE(() -> { // >
1002 byte x = (byte) vh.getAndBitwiseXor(recv, (byte)0x01, Void.class);
1003 });
1004 }
1005
1006 static void testInstanceFieldWrongMethodType(VarHandleTestMethodTypeByte recv, Handles hs) throws Throwable {
1007 for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET)) {
1008 // Incorrect argument types
1009 checkNPE(() -> { // null receiver
1010 byte x = (byte) hs.get(am, methodType(type, VarHandleTestMethodTypeByte.class)).
1011 invokeExact((VarHandleTestMethodTypeByte) null);
1012 });
1013 hs.checkWMTEOrCCE(() -> { // receiver reference class
1014 byte x = (byte) hs.get(am, methodType(type, Class.class)).
1015 invokeExact(Void.class);
1016 });
1017 checkWMTE(() -> { // receiver primitive class
1018 byte x = (byte) hs.get(am, methodType(type, int.class)).
1019 invokeExact(0);
1020 });
1021 // Incorrect return type
1022 checkWMTE(() -> { // reference class
1023 Void x = (Void) hs.get(am, methodType(Void.class, VarHandleTestMethodTypeByte.class)).
1024 invokeExact(recv);
1025 });
1026 checkWMTE(() -> { // primitive class
1027 boolean x = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeByte.class)).
1028 invokeExact(recv);
1029 });
1030 // Incorrect arity
1031 checkWMTE(() -> { // 0
1032 byte x = (byte) hs.get(am, methodType(type)).
1033 invokeExact();
1034 });
1035 checkWMTE(() -> { // >
1036 byte x = (byte) hs.get(am, methodType(type, VarHandleTestMethodTypeByte.class, Class.class)).
1037 invokeExact(recv, Void.class);
1038 });
1039 }
1040
1041 for (TestAccessMode am : testAccessModesOfType(TestAccessType.SET)) {
1042 // Incorrect argument types
1043 checkNPE(() -> { // null receiver
1044 hs.get(am, methodType(void.class, VarHandleTestMethodTypeByte.class, type)).
1045 invokeExact((VarHandleTestMethodTypeByte) null, (byte)0x01);
1046 });
1047 hs.checkWMTEOrCCE(() -> { // receiver reference class
1048 hs.get(am, methodType(void.class, Class.class, type)).
1049 invokeExact(Void.class, (byte)0x01);
1050 });
1051 checkWMTE(() -> { // value reference class
1052 hs.get(am, methodType(void.class, VarHandleTestMethodTypeByte.class, Class.class)).
1053 invokeExact(recv, Void.class);
1054 });
1055 checkWMTE(() -> { // receiver primitive class
1056 hs.get(am, methodType(void.class, int.class, type)).
1057 invokeExact(0, (byte)0x01);
1058 });
1059 // Incorrect arity
1060 checkWMTE(() -> { // 0
1061 hs.get(am, methodType(void.class)).
1062 invokeExact();
1063 });
1064 checkWMTE(() -> { // >
1065 hs.get(am, methodType(void.class, VarHandleTestMethodTypeByte.class, type, Class.class)).
1066 invokeExact(recv, (byte)0x01, Void.class);
1067 });
1068 }
1069
1070 for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
1071 // Incorrect argument types
1072 checkNPE(() -> { // null receiver
1073 boolean r = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeByte.class, type, type)).
1074 invokeExact((VarHandleTestMethodTypeByte) null, (byte)0x01, (byte)0x01);
1075 });
1076 hs.checkWMTEOrCCE(() -> { // receiver reference class
1077 boolean r = (boolean) hs.get(am, methodType(boolean.class, Class.class, type, type)).
1078 invokeExact(Void.class, (byte)0x01, (byte)0x01);
1079 });
1080 checkWMTE(() -> { // expected reference class
1081 boolean r = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeByte.class, Class.class, type)).
1082 invokeExact(recv, Void.class, (byte)0x01);
1083 });
1084 checkWMTE(() -> { // actual reference class
1085 boolean r = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeByte.class, type, Class.class)).
1086 invokeExact(recv, (byte)0x01, Void.class);
1087 });
1088 checkWMTE(() -> { // receiver primitive class
1089 boolean r = (boolean) hs.get(am, methodType(boolean.class, int.class , type, type)).
1090 invokeExact(0, (byte)0x01, (byte)0x01);
1091 });
1092 // Incorrect arity
1093 checkWMTE(() -> { // 0
1094 boolean r = (boolean) hs.get(am, methodType(boolean.class)).
1095 invokeExact();
1096 });
1097 checkWMTE(() -> { // >
1098 boolean r = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeByte.class, type, type, Class.class)).
1099 invokeExact(recv, (byte)0x01, (byte)0x01, Void.class);
1100 });
1101 }
1102
1103 for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
1104 checkNPE(() -> { // null receiver
1105 byte x = (byte) hs.get(am, methodType(type, VarHandleTestMethodTypeByte.class, type, type)).
1106 invokeExact((VarHandleTestMethodTypeByte) null, (byte)0x01, (byte)0x01);
1107 });
1108 hs.checkWMTEOrCCE(() -> { // receiver reference class
1109 byte x = (byte) hs.get(am, methodType(type, Class.class, type, type)).
1110 invokeExact(Void.class, (byte)0x01, (byte)0x01);
1111 });
1112 checkWMTE(() -> { // expected reference class
1113 byte x = (byte) hs.get(am, methodType(type, VarHandleTestMethodTypeByte.class, Class.class, type)).
1114 invokeExact(recv, Void.class, (byte)0x01);
1115 });
1116 checkWMTE(() -> { // actual reference class
1117 byte x = (byte) hs.get(am, methodType(type, VarHandleTestMethodTypeByte.class, type, Class.class)).
1118 invokeExact(recv, (byte)0x01, Void.class);
1119 });
1120 checkWMTE(() -> { // reciever primitive class
1121 byte x = (byte) hs.get(am, methodType(type, int.class , type, type)).
1122 invokeExact(0, (byte)0x01, (byte)0x01);
1123 });
1124 // Incorrect return type
1125 checkWMTE(() -> { // reference class
1126 Void r = (Void) hs.get(am, methodType(Void.class, VarHandleTestMethodTypeByte.class , type, type)).
1127 invokeExact(recv, (byte)0x01, (byte)0x01);
1128 });
1129 checkWMTE(() -> { // primitive class
1130 boolean x = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeByte.class , type, type)).
1131 invokeExact(recv, (byte)0x01, (byte)0x01);
1132 });
1133 // Incorrect arity
1134 checkWMTE(() -> { // 0
1135 byte x = (byte) hs.get(am, methodType(type)).
1136 invokeExact();
1137 });
1138 checkWMTE(() -> { // >
1139 byte x = (byte) hs.get(am, methodType(type, VarHandleTestMethodTypeByte.class, type, type, Class.class)).
1140 invokeExact(recv, (byte)0x01, (byte)0x01, Void.class);
1141 });
1142 }
1143
1144 for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
1145 checkNPE(() -> { // null receiver
1146 byte x = (byte) hs.get(am, methodType(type, VarHandleTestMethodTypeByte.class, type)).
1147 invokeExact((VarHandleTestMethodTypeByte) null, (byte)0x01);
1148 });
1149 hs.checkWMTEOrCCE(() -> { // receiver reference class
1150 byte x = (byte) hs.get(am, methodType(type, Class.class, type)).
1151 invokeExact(Void.class, (byte)0x01);
1152 });
1153 checkWMTE(() -> { // value reference class
1154 byte x = (byte) hs.get(am, methodType(type, VarHandleTestMethodTypeByte.class, Class.class)).
1155 invokeExact(recv, Void.class);
1156 });
1157 checkWMTE(() -> { // reciever primitive class
1158 byte x = (byte) hs.get(am, methodType(type, int.class, type)).
1159 invokeExact(0, (byte)0x01);
1160 });
1161 // Incorrect return type
1162 checkWMTE(() -> { // reference class
1163 Void r = (Void) hs.get(am, methodType(Void.class, VarHandleTestMethodTypeByte.class, type)).
1164 invokeExact(recv, (byte)0x01);
1165 });
1166 checkWMTE(() -> { // primitive class
1167 boolean x = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeByte.class, type)).
1168 invokeExact(recv, (byte)0x01);
1169 });
1170 // Incorrect arity
1171 checkWMTE(() -> { // 0
1172 byte x = (byte) hs.get(am, methodType(type)).
1173 invokeExact();
1174 });
1175 checkWMTE(() -> { // >
1176 byte x = (byte) hs.get(am, methodType(type, VarHandleTestMethodTypeByte.class, type)).
1177 invokeExact(recv, (byte)0x01, Void.class);
1178 });
1179 }
1180
1181 for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) {
1182 checkNPE(() -> { // null receiver
1183 byte x = (byte) hs.get(am, methodType(type, VarHandleTestMethodTypeByte.class, type)).
1184 invokeExact((VarHandleTestMethodTypeByte) null, (byte)0x01);
1185 });
1186 hs.checkWMTEOrCCE(() -> { // receiver reference class
1187 byte x = (byte) hs.get(am, methodType(type, Class.class, type)).
1188 invokeExact(Void.class, (byte)0x01);
1189 });
1190 checkWMTE(() -> { // value reference class
1191 byte x = (byte) hs.get(am, methodType(type, VarHandleTestMethodTypeByte.class, Class.class)).
1192 invokeExact(recv, Void.class);
1193 });
1194 checkWMTE(() -> { // reciever primitive class
1195 byte x = (byte) hs.get(am, methodType(type, int.class, type)).
1196 invokeExact(0, (byte)0x01);
1197 });
1198 // Incorrect return type
1199 checkWMTE(() -> { // reference class
1200 Void r = (Void) hs.get(am, methodType(Void.class, VarHandleTestMethodTypeByte.class, type)).
1201 invokeExact(recv, (byte)0x01);
1202 });
1203 checkWMTE(() -> { // primitive class
1204 boolean x = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeByte.class, type)).
1205 invokeExact(recv, (byte)0x01);
1206 });
1207 // Incorrect arity
1208 checkWMTE(() -> { // 0
1209 byte x = (byte) hs.get(am, methodType(type)).
1210 invokeExact();
1211 });
1212 checkWMTE(() -> { // >
1213 byte x = (byte) hs.get(am, methodType(type, VarHandleTestMethodTypeByte.class, type)).
1214 invokeExact(recv, (byte)0x01, Void.class);
1215 });
1216 }
1217
1218 for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_BITWISE)) {
1219 checkNPE(() -> { // null receiver
1220 byte x = (byte) hs.get(am, methodType(type, VarHandleTestMethodTypeByte.class, type)).
1221 invokeExact((VarHandleTestMethodTypeByte) null, (byte)0x01);
1222 });
1223 hs.checkWMTEOrCCE(() -> { // receiver reference class
1224 byte x = (byte) hs.get(am, methodType(type, Class.class, type)).
1225 invokeExact(Void.class, (byte)0x01);
1226 });
1227 checkWMTE(() -> { // value reference class
1228 byte x = (byte) hs.get(am, methodType(type, VarHandleTestMethodTypeByte.class, Class.class)).
1229 invokeExact(recv, Void.class);
1230 });
1231 checkWMTE(() -> { // reciever primitive class
1232 byte x = (byte) hs.get(am, methodType(type, int.class, type)).
1233 invokeExact(0, (byte)0x01);
1234 });
1235 // Incorrect return type
1236 checkWMTE(() -> { // reference class
1237 Void r = (Void) hs.get(am, methodType(Void.class, VarHandleTestMethodTypeByte.class, type)).
1238 invokeExact(recv, (byte)0x01);
1239 });
1240 checkWMTE(() -> { // primitive class
1241 boolean x = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeByte.class, type)).
1242 invokeExact(recv, (byte)0x01);
1243 });
1244 // Incorrect arity
1245 checkWMTE(() -> { // 0
1246 byte x = (byte) hs.get(am, methodType(type)).
1247 invokeExact();
1248 });
1249 checkWMTE(() -> { // >
1250 byte x = (byte) hs.get(am, methodType(type, VarHandleTestMethodTypeByte.class, type)).
1251 invokeExact(recv, (byte)0x01, Void.class);
1252 });
1253 }
1254 }
1255
1256
1257 static void testStaticFieldWrongMethodType(VarHandle vh) throws Throwable {
1258 // Get
1259 // Incorrect return type
1260 checkWMTE(() -> { // reference class
1261 Void x = (Void) vh.get();
1262 });
1263 checkWMTE(() -> { // primitive class
1264 boolean x = (boolean) vh.get();
1265 });
1266 // Incorrect arity
1267 checkWMTE(() -> { // >
1268 byte x = (byte) vh.get(Void.class);
1269 });
1270
1848 invokeExact();
1849 });
1850 // Incorrect arity
1851 checkWMTE(() -> { // >
1852 byte x = (byte) hs.get(am, methodType(Class.class)).
1853 invokeExact(Void.class);
1854 });
1855 }
1856
1857 for (TestAccessMode am : testAccessModesOfType(TestAccessType.SET)) {
1858 checkWMTE(() -> { // value reference class
1859 hs.get(am, methodType(void.class, Class.class)).
1860 invokeExact(Void.class);
1861 });
1862 // Incorrect arity
1863 checkWMTE(() -> { // 0
1864 hs.get(am, methodType(void.class)).
1865 invokeExact();
1866 });
1867 checkWMTE(() -> { // >
1868 hs.get(am, methodType(void.class, type, Class.class)).
1869 invokeExact((byte)0x01, Void.class);
1870 });
1871 }
1872 for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
1873 // Incorrect argument types
1874 checkWMTE(() -> { // expected reference class
1875 boolean r = (boolean) hs.get(am, methodType(boolean.class, Class.class, type)).
1876 invokeExact(Void.class, (byte)0x01);
1877 });
1878 checkWMTE(() -> { // actual reference class
1879 boolean r = (boolean) hs.get(am, methodType(boolean.class, type, Class.class)).
1880 invokeExact((byte)0x01, Void.class);
1881 });
1882 // Incorrect arity
1883 checkWMTE(() -> { // 0
1884 boolean r = (boolean) hs.get(am, methodType(boolean.class)).
1885 invokeExact();
1886 });
1887 checkWMTE(() -> { // >
1888 boolean r = (boolean) hs.get(am, methodType(boolean.class, type, type, Class.class)).
1889 invokeExact((byte)0x01, (byte)0x01, Void.class);
1890 });
1891 }
1892
1893 for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
1894 // Incorrect argument types
1895 checkWMTE(() -> { // expected reference class
1896 byte x = (byte) hs.get(am, methodType(type, Class.class, type)).
1897 invokeExact(Void.class, (byte)0x01);
1898 });
1899 checkWMTE(() -> { // actual reference class
1900 byte x = (byte) hs.get(am, methodType(type, type, Class.class)).
1901 invokeExact((byte)0x01, Void.class);
1902 });
1903 // Incorrect return type
1904 checkWMTE(() -> { // reference class
1905 Void r = (Void) hs.get(am, methodType(Void.class, type, type)).
1906 invokeExact((byte)0x01, (byte)0x01);
1907 });
1908 checkWMTE(() -> { // primitive class
1909 boolean x = (boolean) hs.get(am, methodType(boolean.class, type, type)).
1910 invokeExact((byte)0x01, (byte)0x01);
1911 });
1912 // Incorrect arity
1913 checkWMTE(() -> { // 0
1914 byte x = (byte) hs.get(am, methodType(type)).
1915 invokeExact();
1916 });
1917 checkWMTE(() -> { // >
1918 byte x = (byte) hs.get(am, methodType(type, type, type, Class.class)).
1919 invokeExact((byte)0x01, (byte)0x01, Void.class);
1920 });
1921 }
1922
1923 for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
1924 // Incorrect argument types
1925 checkWMTE(() -> { // value reference class
1926 byte x = (byte) hs.get(am, methodType(type, Class.class)).
1927 invokeExact(Void.class);
1928 });
1929 // Incorrect return type
1930 checkWMTE(() -> { // reference class
1931 Void r = (Void) hs.get(am, methodType(Void.class, type)).
1932 invokeExact((byte)0x01);
1933 });
1934 checkWMTE(() -> { // primitive class
1935 boolean x = (boolean) hs.get(am, methodType(boolean.class, type)).
1936 invokeExact((byte)0x01);
1937 });
1938 // Incorrect arity
1939 checkWMTE(() -> { // 0
1940 byte x = (byte) hs.get(am, methodType(type)).
1941 invokeExact();
1942 });
1943 checkWMTE(() -> { // >
1944 byte x = (byte) hs.get(am, methodType(type, type, Class.class)).
1945 invokeExact((byte)0x01, Void.class);
1946 });
1947 }
1948
1949 for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) {
1950 // Incorrect argument types
1951 checkWMTE(() -> { // value reference class
1952 byte x = (byte) hs.get(am, methodType(type, Class.class)).
1953 invokeExact(Void.class);
1954 });
1955 // Incorrect return type
1956 checkWMTE(() -> { // reference class
1957 Void r = (Void) hs.get(am, methodType(Void.class, type)).
1958 invokeExact((byte)0x01);
1959 });
1960 checkWMTE(() -> { // primitive class
1961 boolean x = (boolean) hs.get(am, methodType(boolean.class, type)).
1962 invokeExact((byte)0x01);
1963 });
1964 // Incorrect arity
1965 checkWMTE(() -> { // 0
1966 byte x = (byte) hs.get(am, methodType(type)).
1967 invokeExact();
1968 });
1969 checkWMTE(() -> { // >
1970 byte x = (byte) hs.get(am, methodType(type, type, Class.class)).
1971 invokeExact((byte)0x01, Void.class);
1972 });
1973 }
1974
1975 for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_BITWISE)) {
1976 // Incorrect argument types
1977 checkWMTE(() -> { // value reference class
1978 byte x = (byte) hs.get(am, methodType(type, Class.class)).
1979 invokeExact(Void.class);
1980 });
1981 // Incorrect return type
1982 checkWMTE(() -> { // reference class
1983 Void r = (Void) hs.get(am, methodType(Void.class, type)).
1984 invokeExact((byte)0x01);
1985 });
1986 checkWMTE(() -> { // primitive class
1987 boolean x = (boolean) hs.get(am, methodType(boolean.class, type)).
1988 invokeExact((byte)0x01);
1989 });
1990 // Incorrect arity
1991 checkWMTE(() -> { // 0
1992 byte x = (byte) hs.get(am, methodType(type)).
1993 invokeExact();
1994 });
1995 checkWMTE(() -> { // >
1996 byte x = (byte) hs.get(am, methodType(type, type, Class.class)).
1997 invokeExact((byte)0x01, Void.class);
1998 });
1999 }
2000 }
2001
2002
2003 static void testArrayWrongMethodType(VarHandle vh) throws Throwable {
2004 byte[] array = new byte[10];
2005 Arrays.fill(array, (byte)0x01);
2006
2007 // Get
2008 // Incorrect argument types
2009 checkNPE(() -> { // null array
2010 byte x = (byte) vh.get(null, 0);
2011 });
2012 checkCCE(() -> { // array reference class
2013 byte x = (byte) vh.get(Void.class, 0);
2014 });
2015 checkWMTE(() -> { // array primitive class
2016 byte x = (byte) vh.get(0, 0);
2964 });
2965 checkWMTE(() -> { // primitive class
2966 boolean x = (boolean) vh.getAndBitwiseXorRelease(array, 0, (byte)0x01);
2967 });
2968 // Incorrect arity
2969 checkWMTE(() -> { // 0
2970 byte x = (byte) vh.getAndBitwiseXorRelease();
2971 });
2972 checkWMTE(() -> { // >
2973 byte x = (byte) vh.getAndBitwiseXorRelease(array, 0, (byte)0x01, Void.class);
2974 });
2975 }
2976
2977 static void testArrayWrongMethodType(Handles hs) throws Throwable {
2978 byte[] array = new byte[10];
2979 Arrays.fill(array, (byte)0x01);
2980
2981 for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET)) {
2982 // Incorrect argument types
2983 checkNPE(() -> { // null array
2984 byte x = (byte) hs.get(am, methodType(type, byte[].class, int.class)).
2985 invokeExact((byte[]) null, 0);
2986 });
2987 hs.checkWMTEOrCCE(() -> { // array reference class
2988 byte x = (byte) hs.get(am, methodType(type, Class.class, int.class)).
2989 invokeExact(Void.class, 0);
2990 });
2991 checkWMTE(() -> { // array primitive class
2992 byte x = (byte) hs.get(am, methodType(type, int.class, int.class)).
2993 invokeExact(0, 0);
2994 });
2995 checkWMTE(() -> { // index reference class
2996 byte x = (byte) hs.get(am, methodType(type, byte[].class, Class.class)).
2997 invokeExact(array, Void.class);
2998 });
2999 // Incorrect return type
3000 checkWMTE(() -> { // reference class
3001 Void x = (Void) hs.get(am, methodType(Void.class, byte[].class, int.class)).
3002 invokeExact(array, 0);
3003 });
3004 checkWMTE(() -> { // primitive class
3005 boolean x = (boolean) hs.get(am, methodType(boolean.class, byte[].class, int.class)).
3006 invokeExact(array, 0);
3007 });
3008 // Incorrect arity
3009 checkWMTE(() -> { // 0
3010 byte x = (byte) hs.get(am, methodType(type)).
3011 invokeExact();
3012 });
3013 checkWMTE(() -> { // >
3014 byte x = (byte) hs.get(am, methodType(type, byte[].class, int.class, Class.class)).
3015 invokeExact(array, 0, Void.class);
3016 });
3017 }
3018
3019 for (TestAccessMode am : testAccessModesOfType(TestAccessType.SET)) {
3020 // Incorrect argument types
3021 checkNPE(() -> { // null array
3022 hs.get(am, methodType(void.class, byte[].class, int.class, type)).
3023 invokeExact((byte[]) null, 0, (byte)0x01);
3024 });
3025 hs.checkWMTEOrCCE(() -> { // array reference class
3026 hs.get(am, methodType(void.class, Class.class, int.class, type)).
3027 invokeExact(Void.class, 0, (byte)0x01);
3028 });
3029 checkWMTE(() -> { // value reference class
3030 hs.get(am, methodType(void.class, byte[].class, int.class, Class.class)).
3031 invokeExact(array, 0, Void.class);
3032 });
3033 checkWMTE(() -> { // receiver primitive class
3034 hs.get(am, methodType(void.class, int.class, int.class, type)).
3035 invokeExact(0, 0, (byte)0x01);
3036 });
3037 checkWMTE(() -> { // index reference class
3038 hs.get(am, methodType(void.class, byte[].class, Class.class, type)).
3039 invokeExact(array, Void.class, (byte)0x01);
3040 });
3041 // Incorrect arity
3042 checkWMTE(() -> { // 0
3043 hs.get(am, methodType(void.class)).
3044 invokeExact();
3045 });
3046 checkWMTE(() -> { // >
3047 hs.get(am, methodType(void.class, byte[].class, int.class, Class.class)).
3048 invokeExact(array, 0, (byte)0x01, Void.class);
3049 });
3050 }
3051 for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
3052 // Incorrect argument types
3053 checkNPE(() -> { // null receiver
3054 boolean r = (boolean) hs.get(am, methodType(boolean.class, byte[].class, int.class, type, type)).
3055 invokeExact((byte[]) null, 0, (byte)0x01, (byte)0x01);
3056 });
3057 hs.checkWMTEOrCCE(() -> { // receiver reference class
3058 boolean r = (boolean) hs.get(am, methodType(boolean.class, Class.class, int.class, type, type)).
3059 invokeExact(Void.class, 0, (byte)0x01, (byte)0x01);
3060 });
3061 checkWMTE(() -> { // expected reference class
3062 boolean r = (boolean) hs.get(am, methodType(boolean.class, byte[].class, int.class, Class.class, type)).
3063 invokeExact(array, 0, Void.class, (byte)0x01);
3064 });
3065 checkWMTE(() -> { // actual reference class
3066 boolean r = (boolean) hs.get(am, methodType(boolean.class, byte[].class, int.class, type, Class.class)).
3067 invokeExact(array, 0, (byte)0x01, Void.class);
3068 });
3069 checkWMTE(() -> { // receiver primitive class
3070 boolean r = (boolean) hs.get(am, methodType(boolean.class, int.class, int.class, type, type)).
3071 invokeExact(0, 0, (byte)0x01, (byte)0x01);
3072 });
3073 checkWMTE(() -> { // index reference class
3074 boolean r = (boolean) hs.get(am, methodType(boolean.class, byte[].class, Class.class, type, type)).
3075 invokeExact(array, Void.class, (byte)0x01, (byte)0x01);
3076 });
3077 // Incorrect arity
3078 checkWMTE(() -> { // 0
3079 boolean r = (boolean) hs.get(am, methodType(boolean.class)).
3080 invokeExact();
3081 });
3082 checkWMTE(() -> { // >
3083 boolean r = (boolean) hs.get(am, methodType(boolean.class, byte[].class, int.class, type, type, Class.class)).
3084 invokeExact(array, 0, (byte)0x01, (byte)0x01, Void.class);
3085 });
3086 }
3087
3088 for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
3089 // Incorrect argument types
3090 checkNPE(() -> { // null receiver
3091 byte x = (byte) hs.get(am, methodType(type, byte[].class, int.class, type, type)).
3092 invokeExact((byte[]) null, 0, (byte)0x01, (byte)0x01);
3093 });
3094 hs.checkWMTEOrCCE(() -> { // array reference class
3095 byte x = (byte) hs.get(am, methodType(type, Class.class, int.class, type, type)).
3096 invokeExact(Void.class, 0, (byte)0x01, (byte)0x01);
3097 });
3098 checkWMTE(() -> { // expected reference class
3099 byte x = (byte) hs.get(am, methodType(type, byte[].class, int.class, Class.class, type)).
3100 invokeExact(array, 0, Void.class, (byte)0x01);
3101 });
3102 checkWMTE(() -> { // actual reference class
3103 byte x = (byte) hs.get(am, methodType(type, byte[].class, int.class, type, Class.class)).
3104 invokeExact(array, 0, (byte)0x01, Void.class);
3105 });
3106 checkWMTE(() -> { // array primitive class
3107 byte x = (byte) hs.get(am, methodType(type, int.class, int.class, type, type)).
3108 invokeExact(0, 0, (byte)0x01, (byte)0x01);
3109 });
3110 checkWMTE(() -> { // index reference class
3111 byte x = (byte) hs.get(am, methodType(type, byte[].class, Class.class, type, type)).
3112 invokeExact(array, Void.class, (byte)0x01, (byte)0x01);
3113 });
3114 // Incorrect return type
3115 checkWMTE(() -> { // reference class
3116 Void r = (Void) hs.get(am, methodType(Void.class, byte[].class, int.class, type, type)).
3117 invokeExact(array, 0, (byte)0x01, (byte)0x01);
3118 });
3119 checkWMTE(() -> { // primitive class
3120 boolean x = (boolean) hs.get(am, methodType(boolean.class, byte[].class, int.class, type, type)).
3121 invokeExact(array, 0, (byte)0x01, (byte)0x01);
3122 });
3123 // Incorrect arity
3124 checkWMTE(() -> { // 0
3125 byte x = (byte) hs.get(am, methodType(type)).
3126 invokeExact();
3127 });
3128 checkWMTE(() -> { // >
3129 byte x = (byte) hs.get(am, methodType(type, byte[].class, int.class, type, type, Class.class)).
3130 invokeExact(array, 0, (byte)0x01, (byte)0x01, Void.class);
3131 });
3132 }
3133
3134 for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
3135 // Incorrect argument types
3136 checkNPE(() -> { // null array
3137 byte x = (byte) hs.get(am, methodType(type, byte[].class, int.class, type)).
3138 invokeExact((byte[]) null, 0, (byte)0x01);
3139 });
3140 hs.checkWMTEOrCCE(() -> { // array reference class
3141 byte x = (byte) hs.get(am, methodType(type, Class.class, int.class, type)).
3142 invokeExact(Void.class, 0, (byte)0x01);
3143 });
3144 checkWMTE(() -> { // value reference class
3145 byte x = (byte) hs.get(am, methodType(type, byte[].class, int.class, Class.class)).
3146 invokeExact(array, 0, Void.class);
3147 });
3148 checkWMTE(() -> { // array primitive class
3149 byte x = (byte) hs.get(am, methodType(type, int.class, int.class, type)).
3150 invokeExact(0, 0, (byte)0x01);
3151 });
3152 checkWMTE(() -> { // index reference class
3153 byte x = (byte) hs.get(am, methodType(type, byte[].class, Class.class, type)).
3154 invokeExact(array, Void.class, (byte)0x01);
3155 });
3156 // Incorrect return type
3157 checkWMTE(() -> { // reference class
3158 Void r = (Void) hs.get(am, methodType(Void.class, byte[].class, int.class, type)).
3159 invokeExact(array, 0, (byte)0x01);
3160 });
3161 checkWMTE(() -> { // primitive class
3162 boolean x = (boolean) hs.get(am, methodType(boolean.class, byte[].class, int.class, type)).
3163 invokeExact(array, 0, (byte)0x01);
3164 });
3165 // Incorrect arity
3166 checkWMTE(() -> { // 0
3167 byte x = (byte) hs.get(am, methodType(type)).
3168 invokeExact();
3169 });
3170 checkWMTE(() -> { // >
3171 byte x = (byte) hs.get(am, methodType(type, byte[].class, int.class, type, Class.class)).
3172 invokeExact(array, 0, (byte)0x01, Void.class);
3173 });
3174 }
3175
3176 for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) {
3177 // Incorrect argument types
3178 checkNPE(() -> { // null array
3179 byte x = (byte) hs.get(am, methodType(type, byte[].class, int.class, type)).
3180 invokeExact((byte[]) null, 0, (byte)0x01);
3181 });
3182 hs.checkWMTEOrCCE(() -> { // array reference class
3183 byte x = (byte) hs.get(am, methodType(type, Class.class, int.class, type)).
3184 invokeExact(Void.class, 0, (byte)0x01);
3185 });
3186 checkWMTE(() -> { // value reference class
3187 byte x = (byte) hs.get(am, methodType(type, byte[].class, int.class, Class.class)).
3188 invokeExact(array, 0, Void.class);
3189 });
3190 checkWMTE(() -> { // array primitive class
3191 byte x = (byte) hs.get(am, methodType(type, int.class, int.class, type)).
3192 invokeExact(0, 0, (byte)0x01);
3193 });
3194 checkWMTE(() -> { // index reference class
3195 byte x = (byte) hs.get(am, methodType(type, byte[].class, Class.class, type)).
3196 invokeExact(array, Void.class, (byte)0x01);
3197 });
3198 // Incorrect return type
3199 checkWMTE(() -> { // reference class
3200 Void r = (Void) hs.get(am, methodType(Void.class, byte[].class, int.class, type)).
3201 invokeExact(array, 0, (byte)0x01);
3202 });
3203 checkWMTE(() -> { // primitive class
3204 boolean x = (boolean) hs.get(am, methodType(boolean.class, byte[].class, int.class, type)).
3205 invokeExact(array, 0, (byte)0x01);
3206 });
3207 // Incorrect arity
3208 checkWMTE(() -> { // 0
3209 byte x = (byte) hs.get(am, methodType(type)).
3210 invokeExact();
3211 });
3212 checkWMTE(() -> { // >
3213 byte x = (byte) hs.get(am, methodType(type, byte[].class, int.class, type, Class.class)).
3214 invokeExact(array, 0, (byte)0x01, Void.class);
3215 });
3216 }
3217
3218 for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_BITWISE)) {
3219 // Incorrect argument types
3220 checkNPE(() -> { // null array
3221 byte x = (byte) hs.get(am, methodType(type, byte[].class, int.class, type)).
3222 invokeExact((byte[]) null, 0, (byte)0x01);
3223 });
3224 hs.checkWMTEOrCCE(() -> { // array reference class
3225 byte x = (byte) hs.get(am, methodType(type, Class.class, int.class, type)).
3226 invokeExact(Void.class, 0, (byte)0x01);
3227 });
3228 checkWMTE(() -> { // value reference class
3229 byte x = (byte) hs.get(am, methodType(type, byte[].class, int.class, Class.class)).
3230 invokeExact(array, 0, Void.class);
3231 });
3232 checkWMTE(() -> { // array primitive class
3233 byte x = (byte) hs.get(am, methodType(type, int.class, int.class, type)).
3234 invokeExact(0, 0, (byte)0x01);
3235 });
3236 checkWMTE(() -> { // index reference class
3237 byte x = (byte) hs.get(am, methodType(type, byte[].class, Class.class, type)).
3238 invokeExact(array, Void.class, (byte)0x01);
3239 });
3240 // Incorrect return type
3241 checkWMTE(() -> { // reference class
3242 Void r = (Void) hs.get(am, methodType(Void.class, byte[].class, int.class, type)).
3243 invokeExact(array, 0, (byte)0x01);
3244 });
3245 checkWMTE(() -> { // primitive class
3246 boolean x = (boolean) hs.get(am, methodType(boolean.class, byte[].class, int.class, type)).
3247 invokeExact(array, 0, (byte)0x01);
3248 });
3249 // Incorrect arity
3250 checkWMTE(() -> { // 0
3251 byte x = (byte) hs.get(am, methodType(type)).
3252 invokeExact();
3253 });
3254 checkWMTE(() -> { // >
3255 byte x = (byte) hs.get(am, methodType(type, byte[].class, int.class, type, Class.class)).
3256 invokeExact(array, 0, (byte)0x01, Void.class);
3257 });
3258 }
3259 }
3260 }
|