VarHandleTestMethodTypeBoolean.java revision 14958:bb16dd0ce557
1/*
2 * Copyright (c) 2015, 2016 Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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=false VarHandleTestMethodTypeBoolean
29 */
30
31import org.testng.annotations.BeforeClass;
32import org.testng.annotations.DataProvider;
33import org.testng.annotations.Test;
34
35import java.lang.invoke.MethodHandles;
36import java.lang.invoke.VarHandle;
37import java.util.ArrayList;
38import java.util.Arrays;
39import java.util.List;
40
41import static org.testng.Assert.*;
42
43import static java.lang.invoke.MethodType.*;
44
45public class VarHandleTestMethodTypeBoolean extends VarHandleBaseTest {
46    static final boolean static_final_v = true;
47
48    static boolean static_v = true;
49
50    final boolean final_v = true;
51
52    boolean v = true;
53
54    VarHandle vhFinalField;
55
56    VarHandle vhField;
57
58    VarHandle vhStaticField;
59
60    VarHandle vhStaticFinalField;
61
62    VarHandle vhArray;
63
64    @BeforeClass
65    public void setup() throws Exception {
66        vhFinalField = MethodHandles.lookup().findVarHandle(
67                VarHandleTestMethodTypeBoolean.class, "final_v", boolean.class);
68
69        vhField = MethodHandles.lookup().findVarHandle(
70                VarHandleTestMethodTypeBoolean.class, "v", boolean.class);
71
72        vhStaticFinalField = MethodHandles.lookup().findStaticVarHandle(
73            VarHandleTestMethodTypeBoolean.class, "static_final_v", boolean.class);
74
75        vhStaticField = MethodHandles.lookup().findStaticVarHandle(
76            VarHandleTestMethodTypeBoolean.class, "static_v", boolean.class);
77
78        vhArray = MethodHandles.arrayElementVarHandle(boolean[].class);
79    }
80
81    @DataProvider
82    public Object[][] accessTestCaseProvider() throws Exception {
83        List<AccessTestCase<?>> cases = new ArrayList<>();
84
85        cases.add(new VarHandleAccessTestCase("Instance field",
86                                              vhField, vh -> testInstanceFieldWrongMethodType(this, vh),
87                                              false));
88
89        cases.add(new VarHandleAccessTestCase("Static field",
90                                              vhStaticField, VarHandleTestMethodTypeBoolean::testStaticFieldWrongMethodType,
91                                              false));
92
93        cases.add(new VarHandleAccessTestCase("Array",
94                                              vhArray, VarHandleTestMethodTypeBoolean::testArrayWrongMethodType,
95                                              false));
96
97        for (VarHandleToMethodHandle f : VarHandleToMethodHandle.values()) {
98            cases.add(new MethodHandleAccessTestCase("Instance field",
99                                                     vhField, f, hs -> testInstanceFieldWrongMethodType(this, hs),
100                                                     false));
101
102            cases.add(new MethodHandleAccessTestCase("Static field",
103                                                     vhStaticField, f, VarHandleTestMethodTypeBoolean::testStaticFieldWrongMethodType,
104                                                     false));
105
106            cases.add(new MethodHandleAccessTestCase("Array",
107                                                     vhArray, f, VarHandleTestMethodTypeBoolean::testArrayWrongMethodType,
108                                                     false));
109        }
110        // Work around issue with jtreg summary reporting which truncates
111        // the String result of Object.toString to 30 characters, hence
112        // the first dummy argument
113        return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new);
114    }
115
116    @Test(dataProvider = "accessTestCaseProvider")
117    public <T> void testAccess(String desc, AccessTestCase<T> atc) throws Throwable {
118        T t = atc.get();
119        int iters = atc.requiresLoop() ? ITERS : 1;
120        for (int c = 0; c < iters; c++) {
121            atc.testAccess(t);
122        }
123    }
124
125
126    static void testInstanceFieldWrongMethodType(VarHandleTestMethodTypeBoolean recv, VarHandle vh) throws Throwable {
127        // Get
128        // Incorrect argument types
129        checkNPE(() -> { // null receiver
130            boolean x = (boolean) vh.get(null);
131        });
132        checkCCE(() -> { // receiver reference class
133            boolean x = (boolean) vh.get(Void.class);
134        });
135        checkWMTE(() -> { // receiver primitive class
136            boolean x = (boolean) vh.get(0);
137        });
138        // Incorrect return type
139        checkWMTE(() -> { // reference class
140            Void x = (Void) vh.get(recv);
141        });
142        checkWMTE(() -> { // primitive class
143            int x = (int) vh.get(recv);
144        });
145        // Incorrect arity
146        checkWMTE(() -> { // 0
147            boolean x = (boolean) vh.get();
148        });
149        checkWMTE(() -> { // >
150            boolean x = (boolean) vh.get(recv, Void.class);
151        });
152
153
154        // Set
155        // Incorrect argument types
156        checkNPE(() -> { // null receiver
157            vh.set(null, true);
158        });
159        checkCCE(() -> { // receiver reference class
160            vh.set(Void.class, true);
161        });
162        checkWMTE(() -> { // value reference class
163            vh.set(recv, Void.class);
164        });
165        checkWMTE(() -> { // receiver primitive class
166            vh.set(0, true);
167        });
168        // Incorrect arity
169        checkWMTE(() -> { // 0
170            vh.set();
171        });
172        checkWMTE(() -> { // >
173            vh.set(recv, true, Void.class);
174        });
175
176
177        // GetVolatile
178        // Incorrect argument types
179        checkNPE(() -> { // null receiver
180            boolean x = (boolean) vh.getVolatile(null);
181        });
182        checkCCE(() -> { // receiver reference class
183            boolean x = (boolean) vh.getVolatile(Void.class);
184        });
185        checkWMTE(() -> { // receiver primitive class
186            boolean x = (boolean) vh.getVolatile(0);
187        });
188        // Incorrect return type
189        checkWMTE(() -> { // reference class
190            Void x = (Void) vh.getVolatile(recv);
191        });
192        checkWMTE(() -> { // primitive class
193            int x = (int) vh.getVolatile(recv);
194        });
195        // Incorrect arity
196        checkWMTE(() -> { // 0
197            boolean x = (boolean) vh.getVolatile();
198        });
199        checkWMTE(() -> { // >
200            boolean x = (boolean) vh.getVolatile(recv, Void.class);
201        });
202
203
204        // SetVolatile
205        // Incorrect argument types
206        checkNPE(() -> { // null receiver
207            vh.setVolatile(null, true);
208        });
209        checkCCE(() -> { // receiver reference class
210            vh.setVolatile(Void.class, true);
211        });
212        checkWMTE(() -> { // value reference class
213            vh.setVolatile(recv, Void.class);
214        });
215        checkWMTE(() -> { // receiver primitive class
216            vh.setVolatile(0, true);
217        });
218        // Incorrect arity
219        checkWMTE(() -> { // 0
220            vh.setVolatile();
221        });
222        checkWMTE(() -> { // >
223            vh.setVolatile(recv, true, Void.class);
224        });
225
226
227        // GetOpaque
228        // Incorrect argument types
229        checkNPE(() -> { // null receiver
230            boolean x = (boolean) vh.getOpaque(null);
231        });
232        checkCCE(() -> { // receiver reference class
233            boolean x = (boolean) vh.getOpaque(Void.class);
234        });
235        checkWMTE(() -> { // receiver primitive class
236            boolean x = (boolean) vh.getOpaque(0);
237        });
238        // Incorrect return type
239        checkWMTE(() -> { // reference class
240            Void x = (Void) vh.getOpaque(recv);
241        });
242        checkWMTE(() -> { // primitive class
243            int x = (int) vh.getOpaque(recv);
244        });
245        // Incorrect arity
246        checkWMTE(() -> { // 0
247            boolean x = (boolean) vh.getOpaque();
248        });
249        checkWMTE(() -> { // >
250            boolean x = (boolean) vh.getOpaque(recv, Void.class);
251        });
252
253
254        // SetOpaque
255        // Incorrect argument types
256        checkNPE(() -> { // null receiver
257            vh.setOpaque(null, true);
258        });
259        checkCCE(() -> { // receiver reference class
260            vh.setOpaque(Void.class, true);
261        });
262        checkWMTE(() -> { // value reference class
263            vh.setOpaque(recv, Void.class);
264        });
265        checkWMTE(() -> { // receiver primitive class
266            vh.setOpaque(0, true);
267        });
268        // Incorrect arity
269        checkWMTE(() -> { // 0
270            vh.setOpaque();
271        });
272        checkWMTE(() -> { // >
273            vh.setOpaque(recv, true, Void.class);
274        });
275
276
277        // GetAcquire
278        // Incorrect argument types
279        checkNPE(() -> { // null receiver
280            boolean x = (boolean) vh.getAcquire(null);
281        });
282        checkCCE(() -> { // receiver reference class
283            boolean x = (boolean) vh.getAcquire(Void.class);
284        });
285        checkWMTE(() -> { // receiver primitive class
286            boolean x = (boolean) vh.getAcquire(0);
287        });
288        // Incorrect return type
289        checkWMTE(() -> { // reference class
290            Void x = (Void) vh.getAcquire(recv);
291        });
292        checkWMTE(() -> { // primitive class
293            int x = (int) vh.getAcquire(recv);
294        });
295        // Incorrect arity
296        checkWMTE(() -> { // 0
297            boolean x = (boolean) vh.getAcquire();
298        });
299        checkWMTE(() -> { // >
300            boolean x = (boolean) vh.getAcquire(recv, Void.class);
301        });
302
303
304        // SetRelease
305        // Incorrect argument types
306        checkNPE(() -> { // null receiver
307            vh.setRelease(null, true);
308        });
309        checkCCE(() -> { // receiver reference class
310            vh.setRelease(Void.class, true);
311        });
312        checkWMTE(() -> { // value reference class
313            vh.setRelease(recv, Void.class);
314        });
315        checkWMTE(() -> { // receiver primitive class
316            vh.setRelease(0, true);
317        });
318        // Incorrect arity
319        checkWMTE(() -> { // 0
320            vh.setRelease();
321        });
322        checkWMTE(() -> { // >
323            vh.setRelease(recv, true, Void.class);
324        });
325
326
327        // CompareAndSet
328        // Incorrect argument types
329        checkNPE(() -> { // null receiver
330            boolean r = vh.compareAndSet(null, true, true);
331        });
332        checkCCE(() -> { // receiver reference class
333            boolean r = vh.compareAndSet(Void.class, true, true);
334        });
335        checkWMTE(() -> { // expected reference class
336            boolean r = vh.compareAndSet(recv, Void.class, true);
337        });
338        checkWMTE(() -> { // actual reference class
339            boolean r = vh.compareAndSet(recv, true, Void.class);
340        });
341        checkWMTE(() -> { // receiver primitive class
342            boolean r = vh.compareAndSet(0, true, true);
343        });
344        // Incorrect arity
345        checkWMTE(() -> { // 0
346            boolean r = vh.compareAndSet();
347        });
348        checkWMTE(() -> { // >
349            boolean r = vh.compareAndSet(recv, true, true, Void.class);
350        });
351
352
353        // WeakCompareAndSet
354        // Incorrect argument types
355        checkNPE(() -> { // null receiver
356            boolean r = vh.weakCompareAndSet(null, true, true);
357        });
358        checkCCE(() -> { // receiver reference class
359            boolean r = vh.weakCompareAndSet(Void.class, true, true);
360        });
361        checkWMTE(() -> { // expected reference class
362            boolean r = vh.weakCompareAndSet(recv, Void.class, true);
363        });
364        checkWMTE(() -> { // actual reference class
365            boolean r = vh.weakCompareAndSet(recv, true, Void.class);
366        });
367        checkWMTE(() -> { // receiver primitive class
368            boolean r = vh.weakCompareAndSet(0, true, true);
369        });
370        // Incorrect arity
371        checkWMTE(() -> { // 0
372            boolean r = vh.weakCompareAndSet();
373        });
374        checkWMTE(() -> { // >
375            boolean r = vh.weakCompareAndSet(recv, true, true, Void.class);
376        });
377
378
379        // WeakCompareAndSetVolatile
380        // Incorrect argument types
381        checkNPE(() -> { // null receiver
382            boolean r = vh.weakCompareAndSetVolatile(null, true, true);
383        });
384        checkCCE(() -> { // receiver reference class
385            boolean r = vh.weakCompareAndSetVolatile(Void.class, true, true);
386        });
387        checkWMTE(() -> { // expected reference class
388            boolean r = vh.weakCompareAndSetVolatile(recv, Void.class, true);
389        });
390        checkWMTE(() -> { // actual reference class
391            boolean r = vh.weakCompareAndSetVolatile(recv, true, Void.class);
392        });
393        checkWMTE(() -> { // receiver primitive class
394            boolean r = vh.weakCompareAndSetVolatile(0, true, true);
395        });
396        // Incorrect arity
397        checkWMTE(() -> { // 0
398            boolean r = vh.weakCompareAndSetVolatile();
399        });
400        checkWMTE(() -> { // >
401            boolean r = vh.weakCompareAndSetVolatile(recv, true, true, Void.class);
402        });
403
404
405        // WeakCompareAndSetAcquire
406        // Incorrect argument types
407        checkNPE(() -> { // null receiver
408            boolean r = vh.weakCompareAndSetAcquire(null, true, true);
409        });
410        checkCCE(() -> { // receiver reference class
411            boolean r = vh.weakCompareAndSetAcquire(Void.class, true, true);
412        });
413        checkWMTE(() -> { // expected reference class
414            boolean r = vh.weakCompareAndSetAcquire(recv, Void.class, true);
415        });
416        checkWMTE(() -> { // actual reference class
417            boolean r = vh.weakCompareAndSetAcquire(recv, true, Void.class);
418        });
419        checkWMTE(() -> { // receiver primitive class
420            boolean r = vh.weakCompareAndSetAcquire(0, true, true);
421        });
422        // Incorrect arity
423        checkWMTE(() -> { // 0
424            boolean r = vh.weakCompareAndSetAcquire();
425        });
426        checkWMTE(() -> { // >
427            boolean r = vh.weakCompareAndSetAcquire(recv, true, true, Void.class);
428        });
429
430
431        // WeakCompareAndSetRelease
432        // Incorrect argument types
433        checkNPE(() -> { // null receiver
434            boolean r = vh.weakCompareAndSetRelease(null, true, true);
435        });
436        checkCCE(() -> { // receiver reference class
437            boolean r = vh.weakCompareAndSetRelease(Void.class, true, true);
438        });
439        checkWMTE(() -> { // expected reference class
440            boolean r = vh.weakCompareAndSetRelease(recv, Void.class, true);
441        });
442        checkWMTE(() -> { // actual reference class
443            boolean r = vh.weakCompareAndSetRelease(recv, true, Void.class);
444        });
445        checkWMTE(() -> { // receiver primitive class
446            boolean r = vh.weakCompareAndSetRelease(0, true, true);
447        });
448        // Incorrect arity
449        checkWMTE(() -> { // 0
450            boolean r = vh.weakCompareAndSetRelease();
451        });
452        checkWMTE(() -> { // >
453            boolean r = vh.weakCompareAndSetRelease(recv, true, true, Void.class);
454        });
455
456
457        // CompareAndExchange
458        // Incorrect argument types
459        checkNPE(() -> { // null receiver
460            boolean x = (boolean) vh.compareAndExchange(null, true, true);
461        });
462        checkCCE(() -> { // receiver reference class
463            boolean x = (boolean) vh.compareAndExchange(Void.class, true, true);
464        });
465        checkWMTE(() -> { // expected reference class
466            boolean x = (boolean) vh.compareAndExchange(recv, Void.class, true);
467        });
468        checkWMTE(() -> { // actual reference class
469            boolean x = (boolean) vh.compareAndExchange(recv, true, Void.class);
470        });
471        checkWMTE(() -> { // reciever primitive class
472            boolean x = (boolean) vh.compareAndExchange(0, true, true);
473        });
474        // Incorrect return type
475        checkWMTE(() -> { // reference class
476            Void r = (Void) vh.compareAndExchange(recv, true, true);
477        });
478        checkWMTE(() -> { // primitive class
479            int x = (int) vh.compareAndExchange(recv, true, true);
480        });
481        // Incorrect arity
482        checkWMTE(() -> { // 0
483            boolean x = (boolean) vh.compareAndExchange();
484        });
485        checkWMTE(() -> { // >
486            boolean x = (boolean) vh.compareAndExchange(recv, true, true, Void.class);
487        });
488
489
490        // CompareAndExchangeAcquire
491        // Incorrect argument types
492        checkNPE(() -> { // null receiver
493            boolean x = (boolean) vh.compareAndExchangeAcquire(null, true, true);
494        });
495        checkCCE(() -> { // receiver reference class
496            boolean x = (boolean) vh.compareAndExchangeAcquire(Void.class, true, true);
497        });
498        checkWMTE(() -> { // expected reference class
499            boolean x = (boolean) vh.compareAndExchangeAcquire(recv, Void.class, true);
500        });
501        checkWMTE(() -> { // actual reference class
502            boolean x = (boolean) vh.compareAndExchangeAcquire(recv, true, Void.class);
503        });
504        checkWMTE(() -> { // reciever primitive class
505            boolean x = (boolean) vh.compareAndExchangeAcquire(0, true, true);
506        });
507        // Incorrect return type
508        checkWMTE(() -> { // reference class
509            Void r = (Void) vh.compareAndExchangeAcquire(recv, true, true);
510        });
511        checkWMTE(() -> { // primitive class
512            int x = (int) vh.compareAndExchangeAcquire(recv, true, true);
513        });
514        // Incorrect arity
515        checkWMTE(() -> { // 0
516            boolean x = (boolean) vh.compareAndExchangeAcquire();
517        });
518        checkWMTE(() -> { // >
519            boolean x = (boolean) vh.compareAndExchangeAcquire(recv, true, true, Void.class);
520        });
521
522
523        // CompareAndExchangeRelease
524        // Incorrect argument types
525        checkNPE(() -> { // null receiver
526            boolean x = (boolean) vh.compareAndExchangeRelease(null, true, true);
527        });
528        checkCCE(() -> { // receiver reference class
529            boolean x = (boolean) vh.compareAndExchangeRelease(Void.class, true, true);
530        });
531        checkWMTE(() -> { // expected reference class
532            boolean x = (boolean) vh.compareAndExchangeRelease(recv, Void.class, true);
533        });
534        checkWMTE(() -> { // actual reference class
535            boolean x = (boolean) vh.compareAndExchangeRelease(recv, true, Void.class);
536        });
537        checkWMTE(() -> { // reciever primitive class
538            boolean x = (boolean) vh.compareAndExchangeRelease(0, true, true);
539        });
540        // Incorrect return type
541        checkWMTE(() -> { // reference class
542            Void r = (Void) vh.compareAndExchangeRelease(recv, true, true);
543        });
544        checkWMTE(() -> { // primitive class
545            int x = (int) vh.compareAndExchangeRelease(recv, true, true);
546        });
547        // Incorrect arity
548        checkWMTE(() -> { // 0
549            boolean x = (boolean) vh.compareAndExchangeRelease();
550        });
551        checkWMTE(() -> { // >
552            boolean x = (boolean) vh.compareAndExchangeRelease(recv, true, true, Void.class);
553        });
554
555
556        // GetAndSet
557        // Incorrect argument types
558        checkNPE(() -> { // null receiver
559            boolean x = (boolean) vh.getAndSet(null, true);
560        });
561        checkCCE(() -> { // receiver reference class
562            boolean x = (boolean) vh.getAndSet(Void.class, true);
563        });
564        checkWMTE(() -> { // value reference class
565            boolean x = (boolean) vh.getAndSet(recv, Void.class);
566        });
567        checkWMTE(() -> { // reciever primitive class
568            boolean x = (boolean) vh.getAndSet(0, true);
569        });
570        // Incorrect return type
571        checkWMTE(() -> { // reference class
572            Void r = (Void) vh.getAndSet(recv, true);
573        });
574        checkWMTE(() -> { // primitive class
575            int x = (int) vh.getAndSet(recv, true);
576        });
577        // Incorrect arity
578        checkWMTE(() -> { // 0
579            boolean x = (boolean) vh.getAndSet();
580        });
581        checkWMTE(() -> { // >
582            boolean x = (boolean) vh.getAndSet(recv, true, Void.class);
583        });
584
585    }
586
587    static void testInstanceFieldWrongMethodType(VarHandleTestMethodTypeBoolean recv, Handles hs) throws Throwable {
588        for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET)) {
589            // Incorrect argument types
590            checkNPE(() -> { // null receiver
591                boolean x = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeBoolean.class)).
592                    invokeExact((VarHandleTestMethodTypeBoolean) null);
593            });
594            hs.checkWMTEOrCCE(() -> { // receiver reference class
595                boolean x = (boolean) hs.get(am, methodType(boolean.class, Class.class)).
596                    invokeExact(Void.class);
597            });
598            checkWMTE(() -> { // receiver primitive class
599                boolean x = (boolean) hs.get(am, methodType(boolean.class, int.class)).
600                    invokeExact(0);
601            });
602            // Incorrect return type
603            checkWMTE(() -> { // reference class
604                Void x = (Void) hs.get(am, methodType(Void.class, VarHandleTestMethodTypeBoolean.class)).
605                    invokeExact(recv);
606            });
607            checkWMTE(() -> { // primitive class
608                int x = (int) hs.get(am, methodType(int.class, VarHandleTestMethodTypeBoolean.class)).
609                    invokeExact(recv);
610            });
611            // Incorrect arity
612            checkWMTE(() -> { // 0
613                boolean x = (boolean) hs.get(am, methodType(boolean.class)).
614                    invokeExact();
615            });
616            checkWMTE(() -> { // >
617                boolean x = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeBoolean.class, Class.class)).
618                    invokeExact(recv, Void.class);
619            });
620        }
621
622        for (TestAccessMode am : testAccessModesOfType(TestAccessType.SET)) {
623            // Incorrect argument types
624            checkNPE(() -> { // null receiver
625                hs.get(am, methodType(void.class, VarHandleTestMethodTypeBoolean.class, boolean.class)).
626                    invokeExact((VarHandleTestMethodTypeBoolean) null, true);
627            });
628            hs.checkWMTEOrCCE(() -> { // receiver reference class
629                hs.get(am, methodType(void.class, Class.class, boolean.class)).
630                    invokeExact(Void.class, true);
631            });
632            checkWMTE(() -> { // value reference class
633                hs.get(am, methodType(void.class, VarHandleTestMethodTypeBoolean.class, Class.class)).
634                    invokeExact(recv, Void.class);
635            });
636            checkWMTE(() -> { // receiver primitive class
637                hs.get(am, methodType(void.class, int.class, boolean.class)).
638                    invokeExact(0, true);
639            });
640            // Incorrect arity
641            checkWMTE(() -> { // 0
642                hs.get(am, methodType(void.class)).
643                    invokeExact();
644            });
645            checkWMTE(() -> { // >
646                hs.get(am, methodType(void.class, VarHandleTestMethodTypeBoolean.class, boolean.class, Class.class)).
647                    invokeExact(recv, true, Void.class);
648            });
649        }
650
651        for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
652            // Incorrect argument types
653            checkNPE(() -> { // null receiver
654                boolean r = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeBoolean.class, boolean.class, boolean.class)).
655                    invokeExact((VarHandleTestMethodTypeBoolean) null, true, true);
656            });
657            hs.checkWMTEOrCCE(() -> { // receiver reference class
658                boolean r = (boolean) hs.get(am, methodType(boolean.class, Class.class, boolean.class, boolean.class)).
659                    invokeExact(Void.class, true, true);
660            });
661            checkWMTE(() -> { // expected reference class
662                boolean r = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeBoolean.class, Class.class, boolean.class)).
663                    invokeExact(recv, Void.class, true);
664            });
665            checkWMTE(() -> { // actual reference class
666                boolean r = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeBoolean.class, boolean.class, Class.class)).
667                    invokeExact(recv, true, Void.class);
668            });
669            checkWMTE(() -> { // receiver primitive class
670                boolean r = (boolean) hs.get(am, methodType(boolean.class, int.class , boolean.class, boolean.class)).
671                    invokeExact(0, true, true);
672            });
673            // Incorrect arity
674            checkWMTE(() -> { // 0
675                boolean r = (boolean) hs.get(am, methodType(boolean.class)).
676                    invokeExact();
677            });
678            checkWMTE(() -> { // >
679                boolean r = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeBoolean.class, boolean.class, boolean.class, Class.class)).
680                    invokeExact(recv, true, true, Void.class);
681            });
682        }
683
684        for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
685            checkNPE(() -> { // null receiver
686                boolean x = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeBoolean.class, boolean.class, boolean.class)).
687                    invokeExact((VarHandleTestMethodTypeBoolean) null, true, true);
688            });
689            hs.checkWMTEOrCCE(() -> { // receiver reference class
690                boolean x = (boolean) hs.get(am, methodType(boolean.class, Class.class, boolean.class, boolean.class)).
691                    invokeExact(Void.class, true, true);
692            });
693            checkWMTE(() -> { // expected reference class
694                boolean x = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeBoolean.class, Class.class, boolean.class)).
695                    invokeExact(recv, Void.class, true);
696            });
697            checkWMTE(() -> { // actual reference class
698                boolean x = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeBoolean.class, boolean.class, Class.class)).
699                    invokeExact(recv, true, Void.class);
700            });
701            checkWMTE(() -> { // reciever primitive class
702                boolean x = (boolean) hs.get(am, methodType(boolean.class, int.class , boolean.class, boolean.class)).
703                    invokeExact(0, true, true);
704            });
705            // Incorrect return type
706            checkWMTE(() -> { // reference class
707                Void r = (Void) hs.get(am, methodType(Void.class, VarHandleTestMethodTypeBoolean.class , boolean.class, boolean.class)).
708                    invokeExact(recv, true, true);
709            });
710            checkWMTE(() -> { // primitive class
711                int x = (int) hs.get(am, methodType(int.class, VarHandleTestMethodTypeBoolean.class , boolean.class, boolean.class)).
712                    invokeExact(recv, true, true);
713            });
714            // Incorrect arity
715            checkWMTE(() -> { // 0
716                boolean x = (boolean) hs.get(am, methodType(boolean.class)).
717                    invokeExact();
718            });
719            checkWMTE(() -> { // >
720                boolean x = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeBoolean.class, boolean.class, boolean.class, Class.class)).
721                    invokeExact(recv, true, true, Void.class);
722            });
723        }
724
725        for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
726            checkNPE(() -> { // null receiver
727                boolean x = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeBoolean.class, boolean.class)).
728                    invokeExact((VarHandleTestMethodTypeBoolean) null, true);
729            });
730            hs.checkWMTEOrCCE(() -> { // receiver reference class
731                boolean x = (boolean) hs.get(am, methodType(boolean.class, Class.class, boolean.class)).
732                    invokeExact(Void.class, true);
733            });
734            checkWMTE(() -> { // value reference class
735                boolean x = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeBoolean.class, Class.class)).
736                    invokeExact(recv, Void.class);
737            });
738            checkWMTE(() -> { // reciever primitive class
739                boolean x = (boolean) hs.get(am, methodType(boolean.class, int.class, boolean.class)).
740                    invokeExact(0, true);
741            });
742            // Incorrect return type
743            checkWMTE(() -> { // reference class
744                Void r = (Void) hs.get(am, methodType(Void.class, VarHandleTestMethodTypeBoolean.class, boolean.class)).
745                    invokeExact(recv, true);
746            });
747            checkWMTE(() -> { // primitive class
748                int x = (int) hs.get(am, methodType(int.class, VarHandleTestMethodTypeBoolean.class, boolean.class)).
749                    invokeExact(recv, true);
750            });
751            // Incorrect arity
752            checkWMTE(() -> { // 0
753                boolean x = (boolean) hs.get(am, methodType(boolean.class)).
754                    invokeExact();
755            });
756            checkWMTE(() -> { // >
757                boolean x = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeBoolean.class, boolean.class)).
758                    invokeExact(recv, true, Void.class);
759            });
760        }
761
762    }
763
764
765    static void testStaticFieldWrongMethodType(VarHandle vh) throws Throwable {
766        // Get
767        // Incorrect return type
768        checkWMTE(() -> { // reference class
769            Void x = (Void) vh.get();
770        });
771        checkWMTE(() -> { // primitive class
772            int x = (int) vh.get();
773        });
774        // Incorrect arity
775        checkWMTE(() -> { // >
776            boolean x = (boolean) vh.get(Void.class);
777        });
778
779
780        // Set
781        // Incorrect argument types
782        checkWMTE(() -> { // value reference class
783            vh.set(Void.class);
784        });
785        // Incorrect arity
786        checkWMTE(() -> { // 0
787            vh.set();
788        });
789        checkWMTE(() -> { // >
790            vh.set(true, Void.class);
791        });
792
793
794        // GetVolatile
795        // Incorrect return type
796        checkWMTE(() -> { // reference class
797            Void x = (Void) vh.getVolatile();
798        });
799        checkWMTE(() -> { // primitive class
800            int x = (int) vh.getVolatile();
801        });
802        checkWMTE(() -> { // >
803            boolean x = (boolean) vh.getVolatile(Void.class);
804        });
805
806
807        // SetVolatile
808        // Incorrect argument types
809        checkWMTE(() -> { // value reference class
810            vh.setVolatile(Void.class);
811        });
812        // Incorrect arity
813        checkWMTE(() -> { // 0
814            vh.setVolatile();
815        });
816        checkWMTE(() -> { // >
817            vh.setVolatile(true, Void.class);
818        });
819
820
821        // GetOpaque
822        // Incorrect return type
823        checkWMTE(() -> { // reference class
824            Void x = (Void) vh.getOpaque();
825        });
826        checkWMTE(() -> { // primitive class
827            int x = (int) vh.getOpaque();
828        });
829        checkWMTE(() -> { // >
830            boolean x = (boolean) vh.getOpaque(Void.class);
831        });
832
833
834        // SetOpaque
835        // Incorrect argument types
836        checkWMTE(() -> { // value reference class
837            vh.setOpaque(Void.class);
838        });
839        // Incorrect arity
840        checkWMTE(() -> { // 0
841            vh.setOpaque();
842        });
843        checkWMTE(() -> { // >
844            vh.setOpaque(true, Void.class);
845        });
846
847
848        // GetAcquire
849        // Incorrect return type
850        checkWMTE(() -> { // reference class
851            Void x = (Void) vh.getAcquire();
852        });
853        checkWMTE(() -> { // primitive class
854            int x = (int) vh.getAcquire();
855        });
856        checkWMTE(() -> { // >
857            boolean x = (boolean) vh.getAcquire(Void.class);
858        });
859
860
861        // SetRelease
862        // Incorrect argument types
863        checkWMTE(() -> { // value reference class
864            vh.setRelease(Void.class);
865        });
866        // Incorrect arity
867        checkWMTE(() -> { // 0
868            vh.setRelease();
869        });
870        checkWMTE(() -> { // >
871            vh.setRelease(true, Void.class);
872        });
873
874
875        // CompareAndSet
876        // Incorrect argument types
877        checkWMTE(() -> { // expected reference class
878            boolean r = vh.compareAndSet(Void.class, true);
879        });
880        checkWMTE(() -> { // actual reference class
881            boolean r = vh.compareAndSet(true, Void.class);
882        });
883        // Incorrect arity
884        checkWMTE(() -> { // 0
885            boolean r = vh.compareAndSet();
886        });
887        checkWMTE(() -> { // >
888            boolean r = vh.compareAndSet(true, true, Void.class);
889        });
890
891
892        // WeakCompareAndSet
893        // Incorrect argument types
894        checkWMTE(() -> { // expected reference class
895            boolean r = vh.weakCompareAndSet(Void.class, true);
896        });
897        checkWMTE(() -> { // actual reference class
898            boolean r = vh.weakCompareAndSet(true, Void.class);
899        });
900        // Incorrect arity
901        checkWMTE(() -> { // 0
902            boolean r = vh.weakCompareAndSet();
903        });
904        checkWMTE(() -> { // >
905            boolean r = vh.weakCompareAndSet(true, true, Void.class);
906        });
907
908
909        // WeakCompareAndSetVolatile
910        // Incorrect argument types
911        checkWMTE(() -> { // expected reference class
912            boolean r = vh.weakCompareAndSetVolatile(Void.class, true);
913        });
914        checkWMTE(() -> { // actual reference class
915            boolean r = vh.weakCompareAndSetVolatile(true, Void.class);
916        });
917        // Incorrect arity
918        checkWMTE(() -> { // 0
919            boolean r = vh.weakCompareAndSetVolatile();
920        });
921        checkWMTE(() -> { // >
922            boolean r = vh.weakCompareAndSetVolatile(true, true, Void.class);
923        });
924
925
926        // WeakCompareAndSetAcquire
927        // Incorrect argument types
928        checkWMTE(() -> { // expected reference class
929            boolean r = vh.weakCompareAndSetAcquire(Void.class, true);
930        });
931        checkWMTE(() -> { // actual reference class
932            boolean r = vh.weakCompareAndSetAcquire(true, Void.class);
933        });
934        // Incorrect arity
935        checkWMTE(() -> { // 0
936            boolean r = vh.weakCompareAndSetAcquire();
937        });
938        checkWMTE(() -> { // >
939            boolean r = vh.weakCompareAndSetAcquire(true, true, Void.class);
940        });
941
942
943        // WeakCompareAndSetRelease
944        // Incorrect argument types
945        checkWMTE(() -> { // expected reference class
946            boolean r = vh.weakCompareAndSetRelease(Void.class, true);
947        });
948        checkWMTE(() -> { // actual reference class
949            boolean r = vh.weakCompareAndSetRelease(true, Void.class);
950        });
951        // Incorrect arity
952        checkWMTE(() -> { // 0
953            boolean r = vh.weakCompareAndSetRelease();
954        });
955        checkWMTE(() -> { // >
956            boolean r = vh.weakCompareAndSetRelease(true, true, Void.class);
957        });
958
959
960        // CompareAndExchange
961        // Incorrect argument types
962        checkWMTE(() -> { // expected reference class
963            boolean x = (boolean) vh.compareAndExchange(Void.class, true);
964        });
965        checkWMTE(() -> { // actual reference class
966            boolean x = (boolean) vh.compareAndExchange(true, Void.class);
967        });
968        // Incorrect return type
969        checkWMTE(() -> { // reference class
970            Void r = (Void) vh.compareAndExchange(true, true);
971        });
972        checkWMTE(() -> { // primitive class
973            int x = (int) vh.compareAndExchange(true, true);
974        });
975        // Incorrect arity
976        checkWMTE(() -> { // 0
977            boolean x = (boolean) vh.compareAndExchange();
978        });
979        checkWMTE(() -> { // >
980            boolean x = (boolean) vh.compareAndExchange(true, true, Void.class);
981        });
982
983
984        // CompareAndExchangeAcquire
985        // Incorrect argument types
986        checkWMTE(() -> { // expected reference class
987            boolean x = (boolean) vh.compareAndExchangeAcquire(Void.class, true);
988        });
989        checkWMTE(() -> { // actual reference class
990            boolean x = (boolean) vh.compareAndExchangeAcquire(true, Void.class);
991        });
992        // Incorrect return type
993        checkWMTE(() -> { // reference class
994            Void r = (Void) vh.compareAndExchangeAcquire(true, true);
995        });
996        checkWMTE(() -> { // primitive class
997            int x = (int) vh.compareAndExchangeAcquire(true, true);
998        });
999        // Incorrect arity
1000        checkWMTE(() -> { // 0
1001            boolean x = (boolean) vh.compareAndExchangeAcquire();
1002        });
1003        checkWMTE(() -> { // >
1004            boolean x = (boolean) vh.compareAndExchangeAcquire(true, true, Void.class);
1005        });
1006
1007
1008        // CompareAndExchangeRelease
1009        // Incorrect argument types
1010        checkWMTE(() -> { // expected reference class
1011            boolean x = (boolean) vh.compareAndExchangeRelease(Void.class, true);
1012        });
1013        checkWMTE(() -> { // actual reference class
1014            boolean x = (boolean) vh.compareAndExchangeRelease(true, Void.class);
1015        });
1016        // Incorrect return type
1017        checkWMTE(() -> { // reference class
1018            Void r = (Void) vh.compareAndExchangeRelease(true, true);
1019        });
1020        checkWMTE(() -> { // primitive class
1021            int x = (int) vh.compareAndExchangeRelease(true, true);
1022        });
1023        // Incorrect arity
1024        checkWMTE(() -> { // 0
1025            boolean x = (boolean) vh.compareAndExchangeRelease();
1026        });
1027        checkWMTE(() -> { // >
1028            boolean x = (boolean) vh.compareAndExchangeRelease(true, true, Void.class);
1029        });
1030
1031
1032        // GetAndSet
1033        // Incorrect argument types
1034        checkWMTE(() -> { // value reference class
1035            boolean x = (boolean) vh.getAndSet(Void.class);
1036        });
1037        // Incorrect return type
1038        checkWMTE(() -> { // reference class
1039            Void r = (Void) vh.getAndSet(true);
1040        });
1041        checkWMTE(() -> { // primitive class
1042            int x = (int) vh.getAndSet(true);
1043        });
1044        // Incorrect arity
1045        checkWMTE(() -> { // 0
1046            boolean x = (boolean) vh.getAndSet();
1047        });
1048        checkWMTE(() -> { // >
1049            boolean x = (boolean) vh.getAndSet(true, Void.class);
1050        });
1051
1052    }
1053
1054    static void testStaticFieldWrongMethodType(Handles hs) throws Throwable {
1055        int i = 0;
1056
1057        for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET)) {
1058            // Incorrect return type
1059            checkWMTE(() -> { // reference class
1060                Void x = (Void) hs.get(am, methodType(Void.class)).
1061                    invokeExact();
1062            });
1063            checkWMTE(() -> { // primitive class
1064                int x = (int) hs.get(am, methodType(int.class)).
1065                    invokeExact();
1066            });
1067            // Incorrect arity
1068            checkWMTE(() -> { // >
1069                boolean x = (boolean) hs.get(am, methodType(Class.class)).
1070                    invokeExact(Void.class);
1071            });
1072        }
1073
1074        for (TestAccessMode am : testAccessModesOfType(TestAccessType.SET)) {
1075            checkWMTE(() -> { // value reference class
1076                hs.get(am, methodType(void.class, Class.class)).
1077                    invokeExact(Void.class);
1078            });
1079            // Incorrect arity
1080            checkWMTE(() -> { // 0
1081                hs.get(am, methodType(void.class)).
1082                    invokeExact();
1083            });
1084            checkWMTE(() -> { // >
1085                hs.get(am, methodType(void.class, boolean.class, Class.class)).
1086                    invokeExact(true, Void.class);
1087            });
1088        }
1089        for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
1090            // Incorrect argument types
1091            checkWMTE(() -> { // expected reference class
1092                boolean r = (boolean) hs.get(am, methodType(boolean.class, Class.class, boolean.class)).
1093                    invokeExact(Void.class, true);
1094            });
1095            checkWMTE(() -> { // actual reference class
1096                boolean r = (boolean) hs.get(am, methodType(boolean.class, boolean.class, Class.class)).
1097                    invokeExact(true, Void.class);
1098            });
1099            // Incorrect arity
1100            checkWMTE(() -> { // 0
1101                boolean r = (boolean) hs.get(am, methodType(boolean.class)).
1102                    invokeExact();
1103            });
1104            checkWMTE(() -> { // >
1105                boolean r = (boolean) hs.get(am, methodType(boolean.class, boolean.class, boolean.class, Class.class)).
1106                    invokeExact(true, true, Void.class);
1107            });
1108        }
1109
1110        for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
1111            // Incorrect argument types
1112            checkWMTE(() -> { // expected reference class
1113                boolean x = (boolean) hs.get(am, methodType(boolean.class, Class.class, boolean.class)).
1114                    invokeExact(Void.class, true);
1115            });
1116            checkWMTE(() -> { // actual reference class
1117                boolean x = (boolean) hs.get(am, methodType(boolean.class, boolean.class, Class.class)).
1118                    invokeExact(true, Void.class);
1119            });
1120            // Incorrect return type
1121            checkWMTE(() -> { // reference class
1122                Void r = (Void) hs.get(am, methodType(Void.class, boolean.class, boolean.class)).
1123                    invokeExact(true, true);
1124            });
1125            checkWMTE(() -> { // primitive class
1126                int x = (int) hs.get(am, methodType(int.class, boolean.class, boolean.class)).
1127                    invokeExact(true, true);
1128            });
1129            // Incorrect arity
1130            checkWMTE(() -> { // 0
1131                boolean x = (boolean) hs.get(am, methodType(boolean.class)).
1132                    invokeExact();
1133            });
1134            checkWMTE(() -> { // >
1135                boolean x = (boolean) hs.get(am, methodType(boolean.class, boolean.class, boolean.class, Class.class)).
1136                    invokeExact(true, true, Void.class);
1137            });
1138        }
1139
1140        for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
1141            // Incorrect argument types
1142            checkWMTE(() -> { // value reference class
1143                boolean x = (boolean) hs.get(am, methodType(boolean.class, Class.class)).
1144                    invokeExact(Void.class);
1145            });
1146            // Incorrect return type
1147            checkWMTE(() -> { // reference class
1148                Void r = (Void) hs.get(am, methodType(Void.class, boolean.class)).
1149                    invokeExact(true);
1150            });
1151            checkWMTE(() -> { // primitive class
1152                int x = (int) hs.get(am, methodType(int.class, boolean.class)).
1153                    invokeExact(true);
1154            });
1155            // Incorrect arity
1156            checkWMTE(() -> { // 0
1157                boolean x = (boolean) hs.get(am, methodType(boolean.class)).
1158                    invokeExact();
1159            });
1160            checkWMTE(() -> { // >
1161                boolean x = (boolean) hs.get(am, methodType(boolean.class, boolean.class, Class.class)).
1162                    invokeExact(true, Void.class);
1163            });
1164        }
1165
1166    }
1167
1168
1169    static void testArrayWrongMethodType(VarHandle vh) throws Throwable {
1170        boolean[] array = new boolean[10];
1171        Arrays.fill(array, true);
1172
1173        // Get
1174        // Incorrect argument types
1175        checkNPE(() -> { // null array
1176            boolean x = (boolean) vh.get(null, 0);
1177        });
1178        checkCCE(() -> { // array reference class
1179            boolean x = (boolean) vh.get(Void.class, 0);
1180        });
1181        checkWMTE(() -> { // array primitive class
1182            boolean x = (boolean) vh.get(0, 0);
1183        });
1184        checkWMTE(() -> { // index reference class
1185            boolean x = (boolean) vh.get(array, Void.class);
1186        });
1187        // Incorrect return type
1188        checkWMTE(() -> { // reference class
1189            Void x = (Void) vh.get(array, 0);
1190        });
1191        checkWMTE(() -> { // primitive class
1192            int x = (int) vh.get(array, 0);
1193        });
1194        // Incorrect arity
1195        checkWMTE(() -> { // 0
1196            boolean x = (boolean) vh.get();
1197        });
1198        checkWMTE(() -> { // >
1199            boolean x = (boolean) vh.get(array, 0, Void.class);
1200        });
1201
1202
1203        // Set
1204        // Incorrect argument types
1205        checkNPE(() -> { // null array
1206            vh.set(null, 0, true);
1207        });
1208        checkCCE(() -> { // array reference class
1209            vh.set(Void.class, 0, true);
1210        });
1211        checkWMTE(() -> { // value reference class
1212            vh.set(array, 0, Void.class);
1213        });
1214        checkWMTE(() -> { // receiver primitive class
1215            vh.set(0, 0, true);
1216        });
1217        checkWMTE(() -> { // index reference class
1218            vh.set(array, Void.class, true);
1219        });
1220        // Incorrect arity
1221        checkWMTE(() -> { // 0
1222            vh.set();
1223        });
1224        checkWMTE(() -> { // >
1225            vh.set(array, 0, true, Void.class);
1226        });
1227
1228
1229        // GetVolatile
1230        // Incorrect argument types
1231        checkNPE(() -> { // null array
1232            boolean x = (boolean) vh.getVolatile(null, 0);
1233        });
1234        checkCCE(() -> { // array reference class
1235            boolean x = (boolean) vh.getVolatile(Void.class, 0);
1236        });
1237        checkWMTE(() -> { // array primitive class
1238            boolean x = (boolean) vh.getVolatile(0, 0);
1239        });
1240        checkWMTE(() -> { // index reference class
1241            boolean x = (boolean) vh.getVolatile(array, Void.class);
1242        });
1243        // Incorrect return type
1244        checkWMTE(() -> { // reference class
1245            Void x = (Void) vh.getVolatile(array, 0);
1246        });
1247        checkWMTE(() -> { // primitive class
1248            int x = (int) vh.getVolatile(array, 0);
1249        });
1250        // Incorrect arity
1251        checkWMTE(() -> { // 0
1252            boolean x = (boolean) vh.getVolatile();
1253        });
1254        checkWMTE(() -> { // >
1255            boolean x = (boolean) vh.getVolatile(array, 0, Void.class);
1256        });
1257
1258
1259        // SetVolatile
1260        // Incorrect argument types
1261        checkNPE(() -> { // null array
1262            vh.setVolatile(null, 0, true);
1263        });
1264        checkCCE(() -> { // array reference class
1265            vh.setVolatile(Void.class, 0, true);
1266        });
1267        checkWMTE(() -> { // value reference class
1268            vh.setVolatile(array, 0, Void.class);
1269        });
1270        checkWMTE(() -> { // receiver primitive class
1271            vh.setVolatile(0, 0, true);
1272        });
1273        checkWMTE(() -> { // index reference class
1274            vh.setVolatile(array, Void.class, true);
1275        });
1276        // Incorrect arity
1277        checkWMTE(() -> { // 0
1278            vh.setVolatile();
1279        });
1280        checkWMTE(() -> { // >
1281            vh.setVolatile(array, 0, true, Void.class);
1282        });
1283
1284
1285        // GetOpaque
1286        // Incorrect argument types
1287        checkNPE(() -> { // null array
1288            boolean x = (boolean) vh.getOpaque(null, 0);
1289        });
1290        checkCCE(() -> { // array reference class
1291            boolean x = (boolean) vh.getOpaque(Void.class, 0);
1292        });
1293        checkWMTE(() -> { // array primitive class
1294            boolean x = (boolean) vh.getOpaque(0, 0);
1295        });
1296        checkWMTE(() -> { // index reference class
1297            boolean x = (boolean) vh.getOpaque(array, Void.class);
1298        });
1299        // Incorrect return type
1300        checkWMTE(() -> { // reference class
1301            Void x = (Void) vh.getOpaque(array, 0);
1302        });
1303        checkWMTE(() -> { // primitive class
1304            int x = (int) vh.getOpaque(array, 0);
1305        });
1306        // Incorrect arity
1307        checkWMTE(() -> { // 0
1308            boolean x = (boolean) vh.getOpaque();
1309        });
1310        checkWMTE(() -> { // >
1311            boolean x = (boolean) vh.getOpaque(array, 0, Void.class);
1312        });
1313
1314
1315        // SetOpaque
1316        // Incorrect argument types
1317        checkNPE(() -> { // null array
1318            vh.setOpaque(null, 0, true);
1319        });
1320        checkCCE(() -> { // array reference class
1321            vh.setOpaque(Void.class, 0, true);
1322        });
1323        checkWMTE(() -> { // value reference class
1324            vh.setOpaque(array, 0, Void.class);
1325        });
1326        checkWMTE(() -> { // receiver primitive class
1327            vh.setOpaque(0, 0, true);
1328        });
1329        checkWMTE(() -> { // index reference class
1330            vh.setOpaque(array, Void.class, true);
1331        });
1332        // Incorrect arity
1333        checkWMTE(() -> { // 0
1334            vh.setOpaque();
1335        });
1336        checkWMTE(() -> { // >
1337            vh.setOpaque(array, 0, true, Void.class);
1338        });
1339
1340
1341        // GetAcquire
1342        // Incorrect argument types
1343        checkNPE(() -> { // null array
1344            boolean x = (boolean) vh.getAcquire(null, 0);
1345        });
1346        checkCCE(() -> { // array reference class
1347            boolean x = (boolean) vh.getAcquire(Void.class, 0);
1348        });
1349        checkWMTE(() -> { // array primitive class
1350            boolean x = (boolean) vh.getAcquire(0, 0);
1351        });
1352        checkWMTE(() -> { // index reference class
1353            boolean x = (boolean) vh.getAcquire(array, Void.class);
1354        });
1355        // Incorrect return type
1356        checkWMTE(() -> { // reference class
1357            Void x = (Void) vh.getAcquire(array, 0);
1358        });
1359        checkWMTE(() -> { // primitive class
1360            int x = (int) vh.getAcquire(array, 0);
1361        });
1362        // Incorrect arity
1363        checkWMTE(() -> { // 0
1364            boolean x = (boolean) vh.getAcquire();
1365        });
1366        checkWMTE(() -> { // >
1367            boolean x = (boolean) vh.getAcquire(array, 0, Void.class);
1368        });
1369
1370
1371        // SetRelease
1372        // Incorrect argument types
1373        checkNPE(() -> { // null array
1374            vh.setRelease(null, 0, true);
1375        });
1376        checkCCE(() -> { // array reference class
1377            vh.setRelease(Void.class, 0, true);
1378        });
1379        checkWMTE(() -> { // value reference class
1380            vh.setRelease(array, 0, Void.class);
1381        });
1382        checkWMTE(() -> { // receiver primitive class
1383            vh.setRelease(0, 0, true);
1384        });
1385        checkWMTE(() -> { // index reference class
1386            vh.setRelease(array, Void.class, true);
1387        });
1388        // Incorrect arity
1389        checkWMTE(() -> { // 0
1390            vh.setRelease();
1391        });
1392        checkWMTE(() -> { // >
1393            vh.setRelease(array, 0, true, Void.class);
1394        });
1395
1396
1397        // CompareAndSet
1398        // Incorrect argument types
1399        checkNPE(() -> { // null receiver
1400            boolean r = vh.compareAndSet(null, 0, true, true);
1401        });
1402        checkCCE(() -> { // receiver reference class
1403            boolean r = vh.compareAndSet(Void.class, 0, true, true);
1404        });
1405        checkWMTE(() -> { // expected reference class
1406            boolean r = vh.compareAndSet(array, 0, Void.class, true);
1407        });
1408        checkWMTE(() -> { // actual reference class
1409            boolean r = vh.compareAndSet(array, 0, true, Void.class);
1410        });
1411        checkWMTE(() -> { // receiver primitive class
1412            boolean r = vh.compareAndSet(0, 0, true, true);
1413        });
1414        checkWMTE(() -> { // index reference class
1415            boolean r = vh.compareAndSet(array, Void.class, true, true);
1416        });
1417        // Incorrect arity
1418        checkWMTE(() -> { // 0
1419            boolean r = vh.compareAndSet();
1420        });
1421        checkWMTE(() -> { // >
1422            boolean r = vh.compareAndSet(array, 0, true, true, Void.class);
1423        });
1424
1425
1426        // WeakCompareAndSet
1427        // Incorrect argument types
1428        checkNPE(() -> { // null receiver
1429            boolean r = vh.weakCompareAndSet(null, 0, true, true);
1430        });
1431        checkCCE(() -> { // receiver reference class
1432            boolean r = vh.weakCompareAndSet(Void.class, 0, true, true);
1433        });
1434        checkWMTE(() -> { // expected reference class
1435            boolean r = vh.weakCompareAndSet(array, 0, Void.class, true);
1436        });
1437        checkWMTE(() -> { // actual reference class
1438            boolean r = vh.weakCompareAndSet(array, 0, true, Void.class);
1439        });
1440        checkWMTE(() -> { // receiver primitive class
1441            boolean r = vh.weakCompareAndSet(0, 0, true, true);
1442        });
1443        checkWMTE(() -> { // index reference class
1444            boolean r = vh.weakCompareAndSet(array, Void.class, true, true);
1445        });
1446        // Incorrect arity
1447        checkWMTE(() -> { // 0
1448            boolean r = vh.weakCompareAndSet();
1449        });
1450        checkWMTE(() -> { // >
1451            boolean r = vh.weakCompareAndSet(array, 0, true, true, Void.class);
1452        });
1453
1454
1455        // WeakCompareAndSetVolatile
1456        // Incorrect argument types
1457        checkNPE(() -> { // null receiver
1458            boolean r = vh.weakCompareAndSetVolatile(null, 0, true, true);
1459        });
1460        checkCCE(() -> { // receiver reference class
1461            boolean r = vh.weakCompareAndSetVolatile(Void.class, 0, true, true);
1462        });
1463        checkWMTE(() -> { // expected reference class
1464            boolean r = vh.weakCompareAndSetVolatile(array, 0, Void.class, true);
1465        });
1466        checkWMTE(() -> { // actual reference class
1467            boolean r = vh.weakCompareAndSetVolatile(array, 0, true, Void.class);
1468        });
1469        checkWMTE(() -> { // receiver primitive class
1470            boolean r = vh.weakCompareAndSetVolatile(0, 0, true, true);
1471        });
1472        checkWMTE(() -> { // index reference class
1473            boolean r = vh.weakCompareAndSetVolatile(array, Void.class, true, true);
1474        });
1475        // Incorrect arity
1476        checkWMTE(() -> { // 0
1477            boolean r = vh.weakCompareAndSetVolatile();
1478        });
1479        checkWMTE(() -> { // >
1480            boolean r = vh.weakCompareAndSetVolatile(array, 0, true, true, Void.class);
1481        });
1482
1483
1484        // WeakCompareAndSetAcquire
1485        // Incorrect argument types
1486        checkNPE(() -> { // null receiver
1487            boolean r = vh.weakCompareAndSetAcquire(null, 0, true, true);
1488        });
1489        checkCCE(() -> { // receiver reference class
1490            boolean r = vh.weakCompareAndSetAcquire(Void.class, 0, true, true);
1491        });
1492        checkWMTE(() -> { // expected reference class
1493            boolean r = vh.weakCompareAndSetAcquire(array, 0, Void.class, true);
1494        });
1495        checkWMTE(() -> { // actual reference class
1496            boolean r = vh.weakCompareAndSetAcquire(array, 0, true, Void.class);
1497        });
1498        checkWMTE(() -> { // receiver primitive class
1499            boolean r = vh.weakCompareAndSetAcquire(0, 0, true, true);
1500        });
1501        checkWMTE(() -> { // index reference class
1502            boolean r = vh.weakCompareAndSetAcquire(array, Void.class, true, true);
1503        });
1504        // Incorrect arity
1505        checkWMTE(() -> { // 0
1506            boolean r = vh.weakCompareAndSetAcquire();
1507        });
1508        checkWMTE(() -> { // >
1509            boolean r = vh.weakCompareAndSetAcquire(array, 0, true, true, Void.class);
1510        });
1511
1512
1513        // WeakCompareAndSetRelease
1514        // Incorrect argument types
1515        checkNPE(() -> { // null receiver
1516            boolean r = vh.weakCompareAndSetRelease(null, 0, true, true);
1517        });
1518        checkCCE(() -> { // receiver reference class
1519            boolean r = vh.weakCompareAndSetRelease(Void.class, 0, true, true);
1520        });
1521        checkWMTE(() -> { // expected reference class
1522            boolean r = vh.weakCompareAndSetRelease(array, 0, Void.class, true);
1523        });
1524        checkWMTE(() -> { // actual reference class
1525            boolean r = vh.weakCompareAndSetRelease(array, 0, true, Void.class);
1526        });
1527        checkWMTE(() -> { // receiver primitive class
1528            boolean r = vh.weakCompareAndSetRelease(0, 0, true, true);
1529        });
1530        checkWMTE(() -> { // index reference class
1531            boolean r = vh.weakCompareAndSetRelease(array, Void.class, true, true);
1532        });
1533        // Incorrect arity
1534        checkWMTE(() -> { // 0
1535            boolean r = vh.weakCompareAndSetRelease();
1536        });
1537        checkWMTE(() -> { // >
1538            boolean r = vh.weakCompareAndSetRelease(array, 0, true, true, Void.class);
1539        });
1540
1541
1542        // CompareAndExchange
1543        // Incorrect argument types
1544        checkNPE(() -> { // null receiver
1545            boolean x = (boolean) vh.compareAndExchange(null, 0, true, true);
1546        });
1547        checkCCE(() -> { // array reference class
1548            boolean x = (boolean) vh.compareAndExchange(Void.class, 0, true, true);
1549        });
1550        checkWMTE(() -> { // expected reference class
1551            boolean x = (boolean) vh.compareAndExchange(array, 0, Void.class, true);
1552        });
1553        checkWMTE(() -> { // actual reference class
1554            boolean x = (boolean) vh.compareAndExchange(array, 0, true, Void.class);
1555        });
1556        checkWMTE(() -> { // array primitive class
1557            boolean x = (boolean) vh.compareAndExchange(0, 0, true, true);
1558        });
1559        checkWMTE(() -> { // index reference class
1560            boolean x = (boolean) vh.compareAndExchange(array, Void.class, true, true);
1561        });
1562        // Incorrect return type
1563        checkWMTE(() -> { // reference class
1564            Void r = (Void) vh.compareAndExchange(array, 0, true, true);
1565        });
1566        checkWMTE(() -> { // primitive class
1567            int x = (int) vh.compareAndExchange(array, 0, true, true);
1568        });
1569        // Incorrect arity
1570        checkWMTE(() -> { // 0
1571            boolean x = (boolean) vh.compareAndExchange();
1572        });
1573        checkWMTE(() -> { // >
1574            boolean x = (boolean) vh.compareAndExchange(array, 0, true, true, Void.class);
1575        });
1576
1577
1578        // CompareAndExchangeAcquire
1579        // Incorrect argument types
1580        checkNPE(() -> { // null receiver
1581            boolean x = (boolean) vh.compareAndExchangeAcquire(null, 0, true, true);
1582        });
1583        checkCCE(() -> { // array reference class
1584            boolean x = (boolean) vh.compareAndExchangeAcquire(Void.class, 0, true, true);
1585        });
1586        checkWMTE(() -> { // expected reference class
1587            boolean x = (boolean) vh.compareAndExchangeAcquire(array, 0, Void.class, true);
1588        });
1589        checkWMTE(() -> { // actual reference class
1590            boolean x = (boolean) vh.compareAndExchangeAcquire(array, 0, true, Void.class);
1591        });
1592        checkWMTE(() -> { // array primitive class
1593            boolean x = (boolean) vh.compareAndExchangeAcquire(0, 0, true, true);
1594        });
1595        checkWMTE(() -> { // index reference class
1596            boolean x = (boolean) vh.compareAndExchangeAcquire(array, Void.class, true, true);
1597        });
1598        // Incorrect return type
1599        checkWMTE(() -> { // reference class
1600            Void r = (Void) vh.compareAndExchangeAcquire(array, 0, true, true);
1601        });
1602        checkWMTE(() -> { // primitive class
1603            int x = (int) vh.compareAndExchangeAcquire(array, 0, true, true);
1604        });
1605        // Incorrect arity
1606        checkWMTE(() -> { // 0
1607            boolean x = (boolean) vh.compareAndExchangeAcquire();
1608        });
1609        checkWMTE(() -> { // >
1610            boolean x = (boolean) vh.compareAndExchangeAcquire(array, 0, true, true, Void.class);
1611        });
1612
1613
1614        // CompareAndExchangeRelease
1615        // Incorrect argument types
1616        checkNPE(() -> { // null receiver
1617            boolean x = (boolean) vh.compareAndExchangeRelease(null, 0, true, true);
1618        });
1619        checkCCE(() -> { // array reference class
1620            boolean x = (boolean) vh.compareAndExchangeRelease(Void.class, 0, true, true);
1621        });
1622        checkWMTE(() -> { // expected reference class
1623            boolean x = (boolean) vh.compareAndExchangeRelease(array, 0, Void.class, true);
1624        });
1625        checkWMTE(() -> { // actual reference class
1626            boolean x = (boolean) vh.compareAndExchangeRelease(array, 0, true, Void.class);
1627        });
1628        checkWMTE(() -> { // array primitive class
1629            boolean x = (boolean) vh.compareAndExchangeRelease(0, 0, true, true);
1630        });
1631        checkWMTE(() -> { // index reference class
1632            boolean x = (boolean) vh.compareAndExchangeRelease(array, Void.class, true, true);
1633        });
1634        // Incorrect return type
1635        checkWMTE(() -> { // reference class
1636            Void r = (Void) vh.compareAndExchangeRelease(array, 0, true, true);
1637        });
1638        checkWMTE(() -> { // primitive class
1639            int x = (int) vh.compareAndExchangeRelease(array, 0, true, true);
1640        });
1641        // Incorrect arity
1642        checkWMTE(() -> { // 0
1643            boolean x = (boolean) vh.compareAndExchangeRelease();
1644        });
1645        checkWMTE(() -> { // >
1646            boolean x = (boolean) vh.compareAndExchangeRelease(array, 0, true, true, Void.class);
1647        });
1648
1649
1650        // GetAndSet
1651        // Incorrect argument types
1652        checkNPE(() -> { // null array
1653            boolean x = (boolean) vh.getAndSet(null, 0, true);
1654        });
1655        checkCCE(() -> { // array reference class
1656            boolean x = (boolean) vh.getAndSet(Void.class, 0, true);
1657        });
1658        checkWMTE(() -> { // value reference class
1659            boolean x = (boolean) vh.getAndSet(array, 0, Void.class);
1660        });
1661        checkWMTE(() -> { // reciarrayever primitive class
1662            boolean x = (boolean) vh.getAndSet(0, 0, true);
1663        });
1664        checkWMTE(() -> { // index reference class
1665            boolean x = (boolean) vh.getAndSet(array, Void.class, true);
1666        });
1667        // Incorrect return type
1668        checkWMTE(() -> { // reference class
1669            Void r = (Void) vh.getAndSet(array, 0, true);
1670        });
1671        checkWMTE(() -> { // primitive class
1672            int x = (int) vh.getAndSet(array, 0, true);
1673        });
1674        // Incorrect arity
1675        checkWMTE(() -> { // 0
1676            boolean x = (boolean) vh.getAndSet();
1677        });
1678        checkWMTE(() -> { // >
1679            boolean x = (boolean) vh.getAndSet(array, 0, true, Void.class);
1680        });
1681
1682    }
1683
1684    static void testArrayWrongMethodType(Handles hs) throws Throwable {
1685        boolean[] array = new boolean[10];
1686        Arrays.fill(array, true);
1687
1688        for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET)) {
1689            // Incorrect argument types
1690            checkNPE(() -> { // null array
1691                boolean x = (boolean) hs.get(am, methodType(boolean.class, boolean[].class, int.class)).
1692                    invokeExact((boolean[]) null, 0);
1693            });
1694            hs.checkWMTEOrCCE(() -> { // array reference class
1695                boolean x = (boolean) hs.get(am, methodType(boolean.class, Class.class, int.class)).
1696                    invokeExact(Void.class, 0);
1697            });
1698            checkWMTE(() -> { // array primitive class
1699                boolean x = (boolean) hs.get(am, methodType(boolean.class, int.class, int.class)).
1700                    invokeExact(0, 0);
1701            });
1702            checkWMTE(() -> { // index reference class
1703                boolean x = (boolean) hs.get(am, methodType(boolean.class, boolean[].class, Class.class)).
1704                    invokeExact(array, Void.class);
1705            });
1706            // Incorrect return type
1707            checkWMTE(() -> { // reference class
1708                Void x = (Void) hs.get(am, methodType(Void.class, boolean[].class, int.class)).
1709                    invokeExact(array, 0);
1710            });
1711            checkWMTE(() -> { // primitive class
1712                int x = (int) hs.get(am, methodType(int.class, boolean[].class, int.class)).
1713                    invokeExact(array, 0);
1714            });
1715            // Incorrect arity
1716            checkWMTE(() -> { // 0
1717                boolean x = (boolean) hs.get(am, methodType(boolean.class)).
1718                    invokeExact();
1719            });
1720            checkWMTE(() -> { // >
1721                boolean x = (boolean) hs.get(am, methodType(boolean.class, boolean[].class, int.class, Class.class)).
1722                    invokeExact(array, 0, Void.class);
1723            });
1724        }
1725
1726        for (TestAccessMode am : testAccessModesOfType(TestAccessType.SET)) {
1727            // Incorrect argument types
1728            checkNPE(() -> { // null array
1729                hs.get(am, methodType(void.class, boolean[].class, int.class, boolean.class)).
1730                    invokeExact((boolean[]) null, 0, true);
1731            });
1732            hs.checkWMTEOrCCE(() -> { // array reference class
1733                hs.get(am, methodType(void.class, Class.class, int.class, boolean.class)).
1734                    invokeExact(Void.class, 0, true);
1735            });
1736            checkWMTE(() -> { // value reference class
1737                hs.get(am, methodType(void.class, boolean[].class, int.class, Class.class)).
1738                    invokeExact(array, 0, Void.class);
1739            });
1740            checkWMTE(() -> { // receiver primitive class
1741                hs.get(am, methodType(void.class, int.class, int.class, boolean.class)).
1742                    invokeExact(0, 0, true);
1743            });
1744            checkWMTE(() -> { // index reference class
1745                hs.get(am, methodType(void.class, boolean[].class, Class.class, boolean.class)).
1746                    invokeExact(array, Void.class, true);
1747            });
1748            // Incorrect arity
1749            checkWMTE(() -> { // 0
1750                hs.get(am, methodType(void.class)).
1751                    invokeExact();
1752            });
1753            checkWMTE(() -> { // >
1754                hs.get(am, methodType(void.class, boolean[].class, int.class, Class.class)).
1755                    invokeExact(array, 0, true, Void.class);
1756            });
1757        }
1758        for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
1759            // Incorrect argument types
1760            checkNPE(() -> { // null receiver
1761                boolean r = (boolean) hs.get(am, methodType(boolean.class, boolean[].class, int.class, boolean.class, boolean.class)).
1762                    invokeExact((boolean[]) null, 0, true, true);
1763            });
1764            hs.checkWMTEOrCCE(() -> { // receiver reference class
1765                boolean r = (boolean) hs.get(am, methodType(boolean.class, Class.class, int.class, boolean.class, boolean.class)).
1766                    invokeExact(Void.class, 0, true, true);
1767            });
1768            checkWMTE(() -> { // expected reference class
1769                boolean r = (boolean) hs.get(am, methodType(boolean.class, boolean[].class, int.class, Class.class, boolean.class)).
1770                    invokeExact(array, 0, Void.class, true);
1771            });
1772            checkWMTE(() -> { // actual reference class
1773                boolean r = (boolean) hs.get(am, methodType(boolean.class, boolean[].class, int.class, boolean.class, Class.class)).
1774                    invokeExact(array, 0, true, Void.class);
1775            });
1776            checkWMTE(() -> { // receiver primitive class
1777                boolean r = (boolean) hs.get(am, methodType(boolean.class, int.class, int.class, boolean.class, boolean.class)).
1778                    invokeExact(0, 0, true, true);
1779            });
1780            checkWMTE(() -> { // index reference class
1781                boolean r = (boolean) hs.get(am, methodType(boolean.class, boolean[].class, Class.class, boolean.class, boolean.class)).
1782                    invokeExact(array, Void.class, true, true);
1783            });
1784            // Incorrect arity
1785            checkWMTE(() -> { // 0
1786                boolean r = (boolean) hs.get(am, methodType(boolean.class)).
1787                    invokeExact();
1788            });
1789            checkWMTE(() -> { // >
1790                boolean r = (boolean) hs.get(am, methodType(boolean.class, boolean[].class, int.class, boolean.class, boolean.class, Class.class)).
1791                    invokeExact(array, 0, true, true, Void.class);
1792            });
1793        }
1794
1795        for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
1796            // Incorrect argument types
1797            checkNPE(() -> { // null receiver
1798                boolean x = (boolean) hs.get(am, methodType(boolean.class, boolean[].class, int.class, boolean.class, boolean.class)).
1799                    invokeExact((boolean[]) null, 0, true, true);
1800            });
1801            hs.checkWMTEOrCCE(() -> { // array reference class
1802                boolean x = (boolean) hs.get(am, methodType(boolean.class, Class.class, int.class, boolean.class, boolean.class)).
1803                    invokeExact(Void.class, 0, true, true);
1804            });
1805            checkWMTE(() -> { // expected reference class
1806                boolean x = (boolean) hs.get(am, methodType(boolean.class, boolean[].class, int.class, Class.class, boolean.class)).
1807                    invokeExact(array, 0, Void.class, true);
1808            });
1809            checkWMTE(() -> { // actual reference class
1810                boolean x = (boolean) hs.get(am, methodType(boolean.class, boolean[].class, int.class, boolean.class, Class.class)).
1811                    invokeExact(array, 0, true, Void.class);
1812            });
1813            checkWMTE(() -> { // array primitive class
1814                boolean x = (boolean) hs.get(am, methodType(boolean.class, int.class, int.class, boolean.class, boolean.class)).
1815                    invokeExact(0, 0, true, true);
1816            });
1817            checkWMTE(() -> { // index reference class
1818                boolean x = (boolean) hs.get(am, methodType(boolean.class, boolean[].class, Class.class, boolean.class, boolean.class)).
1819                    invokeExact(array, Void.class, true, true);
1820            });
1821            // Incorrect return type
1822            checkWMTE(() -> { // reference class
1823                Void r = (Void) hs.get(am, methodType(Void.class, boolean[].class, int.class, boolean.class, boolean.class)).
1824                    invokeExact(array, 0, true, true);
1825            });
1826            checkWMTE(() -> { // primitive class
1827                int x = (int) hs.get(am, methodType(int.class, boolean[].class, int.class, boolean.class, boolean.class)).
1828                    invokeExact(array, 0, true, true);
1829            });
1830            // Incorrect arity
1831            checkWMTE(() -> { // 0
1832                boolean x = (boolean) hs.get(am, methodType(boolean.class)).
1833                    invokeExact();
1834            });
1835            checkWMTE(() -> { // >
1836                boolean x = (boolean) hs.get(am, methodType(boolean.class, boolean[].class, int.class, boolean.class, boolean.class, Class.class)).
1837                    invokeExact(array, 0, true, true, Void.class);
1838            });
1839        }
1840
1841        for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
1842            // Incorrect argument types
1843            checkNPE(() -> { // null array
1844                boolean x = (boolean) hs.get(am, methodType(boolean.class, boolean[].class, int.class, boolean.class)).
1845                    invokeExact((boolean[]) null, 0, true);
1846            });
1847            hs.checkWMTEOrCCE(() -> { // array reference class
1848                boolean x = (boolean) hs.get(am, methodType(boolean.class, Class.class, int.class, boolean.class)).
1849                    invokeExact(Void.class, 0, true);
1850            });
1851            checkWMTE(() -> { // value reference class
1852                boolean x = (boolean) hs.get(am, methodType(boolean.class, boolean[].class, int.class, Class.class)).
1853                    invokeExact(array, 0, Void.class);
1854            });
1855            checkWMTE(() -> { // array primitive class
1856                boolean x = (boolean) hs.get(am, methodType(boolean.class, int.class, int.class, boolean.class)).
1857                    invokeExact(0, 0, true);
1858            });
1859            checkWMTE(() -> { // index reference class
1860                boolean x = (boolean) hs.get(am, methodType(boolean.class, boolean[].class, Class.class, boolean.class)).
1861                    invokeExact(array, Void.class, true);
1862            });
1863            // Incorrect return type
1864            checkWMTE(() -> { // reference class
1865                Void r = (Void) hs.get(am, methodType(Void.class, boolean[].class, int.class, boolean.class)).
1866                    invokeExact(array, 0, true);
1867            });
1868            checkWMTE(() -> { // primitive class
1869                int x = (int) hs.get(am, methodType(int.class, boolean[].class, int.class, boolean.class)).
1870                    invokeExact(array, 0, true);
1871            });
1872            // Incorrect arity
1873            checkWMTE(() -> { // 0
1874                boolean x = (boolean) hs.get(am, methodType(boolean.class)).
1875                    invokeExact();
1876            });
1877            checkWMTE(() -> { // >
1878                boolean x = (boolean) hs.get(am, methodType(boolean.class, boolean[].class, int.class, boolean.class, Class.class)).
1879                    invokeExact(array, 0, true, Void.class);
1880            });
1881        }
1882
1883    }
1884}
1885
1886