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