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