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