1 /*
   2  * Copyright (c) 2015, 2020, 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  * @run testng/othervm VarHandleTestMethodTypeString
  30  * @run testng/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=true -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true VarHandleTestMethodTypeString
  31  * @run testng/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=false VarHandleTestMethodTypeString
  32  * @run testng/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true VarHandleTestMethodTypeString
  33  */
  34 
  35 import org.testng.annotations.BeforeClass;
  36 import org.testng.annotations.DataProvider;
  37 import org.testng.annotations.Test;
  38 
  39 import java.lang.invoke.MethodHandles;
  40 import java.lang.invoke.VarHandle;
  41 import java.util.ArrayList;
  42 import java.util.Arrays;
  43 import java.util.List;
  44 
  45 import static org.testng.Assert.*;
  46 
  47 import static java.lang.invoke.MethodType.*;
  48 
  49 public class VarHandleTestMethodTypeString extends VarHandleBaseTest {
  50     static final Class<?> type = String.class;
  51 
  52     static final String static_final_v = "foo";
  53 
  54     static String static_v = "foo";
  55 
  56     final String final_v = "foo";
  57 
  58     String v = "foo";
  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                 VarHandleTestMethodTypeString.class, "final_v", type);
  74 
  75         vhField = MethodHandles.lookup().findVarHandle(
  76                 VarHandleTestMethodTypeString.class, "v", type);
  77 
  78         vhStaticFinalField = MethodHandles.lookup().findStaticVarHandle(
  79             VarHandleTestMethodTypeString.class, "static_final_v", type);
  80 
  81         vhStaticField = MethodHandles.lookup().findStaticVarHandle(
  82             VarHandleTestMethodTypeString.class, "static_v", type);
  83 
  84         vhArray = MethodHandles.arrayElementVarHandle(String[].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, VarHandleTestMethodTypeString::testStaticFieldWrongMethodType,
  97                                               false));
  98 
  99         cases.add(new VarHandleAccessTestCase("Array",
 100                                               vhArray, VarHandleTestMethodTypeString::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, VarHandleTestMethodTypeString::testStaticFieldWrongMethodType,
 110                                                      false));
 111 
 112             cases.add(new MethodHandleAccessTestCase("Array",
 113                                                      vhArray, f, VarHandleTestMethodTypeString::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(VarHandleTestMethodTypeString recv, VarHandle vh) throws Throwable {
 133         // Get
 134         // Incorrect argument types
 135         checkNPE(() -> { // null receiver
 136             String x = (String) vh.get(null);
 137         });
 138         checkCCE(() -> { // receiver reference class
 139             String x = (String) vh.get(Void.class);
 140         });
 141         checkWMTE(() -> { // receiver primitive class
 142             String x = (String) 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             String x = (String) vh.get();
 154         });
 155         checkWMTE(() -> { // >
 156             String x = (String) vh.get(recv, Void.class);
 157         });
 158 
 159 
 160         // Set
 161         // Incorrect argument types
 162         checkNPE(() -> { // null receiver
 163             vh.set(null, "foo");
 164         });
 165         checkCCE(() -> { // receiver reference class
 166             vh.set(Void.class, "foo");
 167         });
 168         checkCCE(() -> { // value reference class
 169             vh.set(recv, Void.class);
 170         });
 171         checkWMTE(() -> { // receiver primitive class
 172             vh.set(0, "foo");
 173         });
 174         // Incorrect arity
 175         checkWMTE(() -> { // 0
 176             vh.set();
 177         });
 178         checkWMTE(() -> { // >
 179             vh.set(recv, "foo", Void.class);
 180         });
 181 
 182 
 183         // GetVolatile
 184         // Incorrect argument types
 185         checkNPE(() -> { // null receiver
 186             String x = (String) vh.getVolatile(null);
 187         });
 188         checkCCE(() -> { // receiver reference class
 189             String x = (String) vh.getVolatile(Void.class);
 190         });
 191         checkWMTE(() -> { // receiver primitive class
 192             String x = (String) 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             String x = (String) vh.getVolatile();
 204         });
 205         checkWMTE(() -> { // >
 206             String x = (String) vh.getVolatile(recv, Void.class);
 207         });
 208 
 209 
 210         // SetVolatile
 211         // Incorrect argument types
 212         checkNPE(() -> { // null receiver
 213             vh.setVolatile(null, "foo");
 214         });
 215         checkCCE(() -> { // receiver reference class
 216             vh.setVolatile(Void.class, "foo");
 217         });
 218         checkCCE(() -> { // value reference class
 219             vh.setVolatile(recv, Void.class);
 220         });
 221         checkWMTE(() -> { // receiver primitive class
 222             vh.setVolatile(0, "foo");
 223         });
 224         // Incorrect arity
 225         checkWMTE(() -> { // 0
 226             vh.setVolatile();
 227         });
 228         checkWMTE(() -> { // >
 229             vh.setVolatile(recv, "foo", Void.class);
 230         });
 231 
 232 
 233         // GetOpaque
 234         // Incorrect argument types
 235         checkNPE(() -> { // null receiver
 236             String x = (String) vh.getOpaque(null);
 237         });
 238         checkCCE(() -> { // receiver reference class
 239             String x = (String) vh.getOpaque(Void.class);
 240         });
 241         checkWMTE(() -> { // receiver primitive class
 242             String x = (String) 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             String x = (String) vh.getOpaque();
 254         });
 255         checkWMTE(() -> { // >
 256             String x = (String) vh.getOpaque(recv, Void.class);
 257         });
 258 
 259 
 260         // SetOpaque
 261         // Incorrect argument types
 262         checkNPE(() -> { // null receiver
 263             vh.setOpaque(null, "foo");
 264         });
 265         checkCCE(() -> { // receiver reference class
 266             vh.setOpaque(Void.class, "foo");
 267         });
 268         checkCCE(() -> { // value reference class
 269             vh.setOpaque(recv, Void.class);
 270         });
 271         checkWMTE(() -> { // receiver primitive class
 272             vh.setOpaque(0, "foo");
 273         });
 274         // Incorrect arity
 275         checkWMTE(() -> { // 0
 276             vh.setOpaque();
 277         });
 278         checkWMTE(() -> { // >
 279             vh.setOpaque(recv, "foo", Void.class);
 280         });
 281 
 282 
 283         // GetAcquire
 284         // Incorrect argument types
 285         checkNPE(() -> { // null receiver
 286             String x = (String) vh.getAcquire(null);
 287         });
 288         checkCCE(() -> { // receiver reference class
 289             String x = (String) vh.getAcquire(Void.class);
 290         });
 291         checkWMTE(() -> { // receiver primitive class
 292             String x = (String) 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             String x = (String) vh.getAcquire();
 304         });
 305         checkWMTE(() -> { // >
 306             String x = (String) vh.getAcquire(recv, Void.class);
 307         });
 308 
 309 
 310         // SetRelease
 311         // Incorrect argument types
 312         checkNPE(() -> { // null receiver
 313             vh.setRelease(null, "foo");
 314         });
 315         checkCCE(() -> { // receiver reference class
 316             vh.setRelease(Void.class, "foo");
 317         });
 318         checkCCE(() -> { // value reference class
 319             vh.setRelease(recv, Void.class);
 320         });
 321         checkWMTE(() -> { // receiver primitive class
 322             vh.setRelease(0, "foo");
 323         });
 324         // Incorrect arity
 325         checkWMTE(() -> { // 0
 326             vh.setRelease();
 327         });
 328         checkWMTE(() -> { // >
 329             vh.setRelease(recv, "foo", Void.class);
 330         });
 331 
 332 
 333         // CompareAndSet
 334         // Incorrect argument types
 335         checkNPE(() -> { // null receiver
 336             boolean r = vh.compareAndSet(null, "foo", "foo");
 337         });
 338         checkCCE(() -> { // receiver reference class
 339             boolean r = vh.compareAndSet(Void.class, "foo", "foo");
 340         });
 341         checkCCE(() -> { // expected reference class
 342             boolean r = vh.compareAndSet(recv, Void.class, "foo");
 343         });
 344         checkCCE(() -> { // actual reference class
 345             boolean r = vh.compareAndSet(recv, "foo", Void.class);
 346         });
 347         checkWMTE(() -> { // receiver primitive class
 348             boolean r = vh.compareAndSet(0, "foo", "foo");
 349         });
 350         // Incorrect arity
 351         checkWMTE(() -> { // 0
 352             boolean r = vh.compareAndSet();
 353         });
 354         checkWMTE(() -> { // >
 355             boolean r = vh.compareAndSet(recv, "foo", "foo", Void.class);
 356         });
 357 
 358 
 359         // WeakCompareAndSet
 360         // Incorrect argument types
 361         checkNPE(() -> { // null receiver
 362             boolean r = vh.weakCompareAndSetPlain(null, "foo", "foo");
 363         });
 364         checkCCE(() -> { // receiver reference class
 365             boolean r = vh.weakCompareAndSetPlain(Void.class, "foo", "foo");
 366         });
 367         checkCCE(() -> { // expected reference class
 368             boolean r = vh.weakCompareAndSetPlain(recv, Void.class, "foo");
 369         });
 370         checkCCE(() -> { // actual reference class
 371             boolean r = vh.weakCompareAndSetPlain(recv, "foo", Void.class);
 372         });
 373         checkWMTE(() -> { // receiver primitive class
 374             boolean r = vh.weakCompareAndSetPlain(0, "foo", "foo");
 375         });
 376         // Incorrect arity
 377         checkWMTE(() -> { // 0
 378             boolean r = vh.weakCompareAndSetPlain();
 379         });
 380         checkWMTE(() -> { // >
 381             boolean r = vh.weakCompareAndSetPlain(recv, "foo", "foo", Void.class);
 382         });
 383 
 384 
 385         // WeakCompareAndSetVolatile
 386         // Incorrect argument types
 387         checkNPE(() -> { // null receiver
 388             boolean r = vh.weakCompareAndSet(null, "foo", "foo");
 389         });
 390         checkCCE(() -> { // receiver reference class
 391             boolean r = vh.weakCompareAndSet(Void.class, "foo", "foo");
 392         });
 393         checkCCE(() -> { // expected reference class
 394             boolean r = vh.weakCompareAndSet(recv, Void.class, "foo");
 395         });
 396         checkCCE(() -> { // actual reference class
 397             boolean r = vh.weakCompareAndSet(recv, "foo", Void.class);
 398         });
 399         checkWMTE(() -> { // receiver primitive class
 400             boolean r = vh.weakCompareAndSet(0, "foo", "foo");
 401         });
 402         // Incorrect arity
 403         checkWMTE(() -> { // 0
 404             boolean r = vh.weakCompareAndSet();
 405         });
 406         checkWMTE(() -> { // >
 407             boolean r = vh.weakCompareAndSet(recv, "foo", "foo", Void.class);
 408         });
 409 
 410 
 411         // WeakCompareAndSetAcquire
 412         // Incorrect argument types
 413         checkNPE(() -> { // null receiver
 414             boolean r = vh.weakCompareAndSetAcquire(null, "foo", "foo");
 415         });
 416         checkCCE(() -> { // receiver reference class
 417             boolean r = vh.weakCompareAndSetAcquire(Void.class, "foo", "foo");
 418         });
 419         checkCCE(() -> { // expected reference class
 420             boolean r = vh.weakCompareAndSetAcquire(recv, Void.class, "foo");
 421         });
 422         checkCCE(() -> { // actual reference class
 423             boolean r = vh.weakCompareAndSetAcquire(recv, "foo", Void.class);
 424         });
 425         checkWMTE(() -> { // receiver primitive class
 426             boolean r = vh.weakCompareAndSetAcquire(0, "foo", "foo");
 427         });
 428         // Incorrect arity
 429         checkWMTE(() -> { // 0
 430             boolean r = vh.weakCompareAndSetAcquire();
 431         });
 432         checkWMTE(() -> { // >
 433             boolean r = vh.weakCompareAndSetAcquire(recv, "foo", "foo", Void.class);
 434         });
 435 
 436 
 437         // WeakCompareAndSetRelease
 438         // Incorrect argument types
 439         checkNPE(() -> { // null receiver
 440             boolean r = vh.weakCompareAndSetRelease(null, "foo", "foo");
 441         });
 442         checkCCE(() -> { // receiver reference class
 443             boolean r = vh.weakCompareAndSetRelease(Void.class, "foo", "foo");
 444         });
 445         checkCCE(() -> { // expected reference class
 446             boolean r = vh.weakCompareAndSetRelease(recv, Void.class, "foo");
 447         });
 448         checkCCE(() -> { // actual reference class
 449             boolean r = vh.weakCompareAndSetRelease(recv, "foo", Void.class);
 450         });
 451         checkWMTE(() -> { // receiver primitive class
 452             boolean r = vh.weakCompareAndSetRelease(0, "foo", "foo");
 453         });
 454         // Incorrect arity
 455         checkWMTE(() -> { // 0
 456             boolean r = vh.weakCompareAndSetRelease();
 457         });
 458         checkWMTE(() -> { // >
 459             boolean r = vh.weakCompareAndSetRelease(recv, "foo", "foo", Void.class);
 460         });
 461 
 462 
 463         // CompareAndExchange
 464         // Incorrect argument types
 465         checkNPE(() -> { // null receiver
 466             String x = (String) vh.compareAndExchange(null, "foo", "foo");
 467         });
 468         checkCCE(() -> { // receiver reference class
 469             String x = (String) vh.compareAndExchange(Void.class, "foo", "foo");
 470         });
 471         checkCCE(() -> { // expected reference class
 472             String x = (String) vh.compareAndExchange(recv, Void.class, "foo");
 473         });
 474         checkCCE(() -> { // actual reference class
 475             String x = (String) vh.compareAndExchange(recv, "foo", Void.class);
 476         });
 477         checkWMTE(() -> { // reciever primitive class
 478             String x = (String) vh.compareAndExchange(0, "foo", "foo");
 479         });
 480         // Incorrect return type
 481         checkCCE(() -> { // reference class
 482             Void r = (Void) vh.compareAndExchange(recv, "foo", "foo");
 483         });
 484         checkWMTE(() -> { // primitive class
 485             boolean x = (boolean) vh.compareAndExchange(recv, "foo", "foo");
 486         });
 487         // Incorrect arity
 488         checkWMTE(() -> { // 0
 489             String x = (String) vh.compareAndExchange();
 490         });
 491         checkWMTE(() -> { // >
 492             String x = (String) vh.compareAndExchange(recv, "foo", "foo", Void.class);
 493         });
 494 
 495 
 496         // CompareAndExchangeAcquire
 497         // Incorrect argument types
 498         checkNPE(() -> { // null receiver
 499             String x = (String) vh.compareAndExchangeAcquire(null, "foo", "foo");
 500         });
 501         checkCCE(() -> { // receiver reference class
 502             String x = (String) vh.compareAndExchangeAcquire(Void.class, "foo", "foo");
 503         });
 504         checkCCE(() -> { // expected reference class
 505             String x = (String) vh.compareAndExchangeAcquire(recv, Void.class, "foo");
 506         });
 507         checkCCE(() -> { // actual reference class
 508             String x = (String) vh.compareAndExchangeAcquire(recv, "foo", Void.class);
 509         });
 510         checkWMTE(() -> { // reciever primitive class
 511             String x = (String) vh.compareAndExchangeAcquire(0, "foo", "foo");
 512         });
 513         // Incorrect return type
 514         checkCCE(() -> { // reference class
 515             Void r = (Void) vh.compareAndExchangeAcquire(recv, "foo", "foo");
 516         });
 517         checkWMTE(() -> { // primitive class
 518             boolean x = (boolean) vh.compareAndExchangeAcquire(recv, "foo", "foo");
 519         });
 520         // Incorrect arity
 521         checkWMTE(() -> { // 0
 522             String x = (String) vh.compareAndExchangeAcquire();
 523         });
 524         checkWMTE(() -> { // >
 525             String x = (String) vh.compareAndExchangeAcquire(recv, "foo", "foo", Void.class);
 526         });
 527 
 528 
 529         // CompareAndExchangeRelease
 530         // Incorrect argument types
 531         checkNPE(() -> { // null receiver
 532             String x = (String) vh.compareAndExchangeRelease(null, "foo", "foo");
 533         });
 534         checkCCE(() -> { // receiver reference class
 535             String x = (String) vh.compareAndExchangeRelease(Void.class, "foo", "foo");
 536         });
 537         checkCCE(() -> { // expected reference class
 538             String x = (String) vh.compareAndExchangeRelease(recv, Void.class, "foo");
 539         });
 540         checkCCE(() -> { // actual reference class
 541             String x = (String) vh.compareAndExchangeRelease(recv, "foo", Void.class);
 542         });
 543         checkWMTE(() -> { // reciever primitive class
 544             String x = (String) vh.compareAndExchangeRelease(0, "foo", "foo");
 545         });
 546         // Incorrect return type
 547         checkCCE(() -> { // reference class
 548             Void r = (Void) vh.compareAndExchangeRelease(recv, "foo", "foo");
 549         });
 550         checkWMTE(() -> { // primitive class
 551             boolean x = (boolean) vh.compareAndExchangeRelease(recv, "foo", "foo");
 552         });
 553         // Incorrect arity
 554         checkWMTE(() -> { // 0
 555             String x = (String) vh.compareAndExchangeRelease();
 556         });
 557         checkWMTE(() -> { // >
 558             String x = (String) vh.compareAndExchangeRelease(recv, "foo", "foo", Void.class);
 559         });
 560 
 561 
 562         // GetAndSet
 563         // Incorrect argument types
 564         checkNPE(() -> { // null receiver
 565             String x = (String) vh.getAndSet(null, "foo");
 566         });
 567         checkCCE(() -> { // receiver reference class
 568             String x = (String) vh.getAndSet(Void.class, "foo");
 569         });
 570         checkCCE(() -> { // value reference class
 571             String x = (String) vh.getAndSet(recv, Void.class);
 572         });
 573         checkWMTE(() -> { // reciever primitive class
 574             String x = (String) vh.getAndSet(0, "foo");
 575         });
 576         // Incorrect return type
 577         checkCCE(() -> { // reference class
 578             Void r = (Void) vh.getAndSet(recv, "foo");
 579         });
 580         checkWMTE(() -> { // primitive class
 581             boolean x = (boolean) vh.getAndSet(recv, "foo");
 582         });
 583         // Incorrect arity
 584         checkWMTE(() -> { // 0
 585             String x = (String) vh.getAndSet();
 586         });
 587         checkWMTE(() -> { // >
 588             String x = (String) vh.getAndSet(recv, "foo", Void.class);
 589         });
 590 
 591         // GetAndSetAcquire
 592         // Incorrect argument types
 593         checkNPE(() -> { // null receiver
 594             String x = (String) vh.getAndSetAcquire(null, "foo");
 595         });
 596         checkCCE(() -> { // receiver reference class
 597             String x = (String) vh.getAndSetAcquire(Void.class, "foo");
 598         });
 599         checkCCE(() -> { // value reference class
 600             String x = (String) vh.getAndSetAcquire(recv, Void.class);
 601         });
 602         checkWMTE(() -> { // reciever primitive class
 603             String x = (String) vh.getAndSetAcquire(0, "foo");
 604         });
 605         // Incorrect return type
 606         checkCCE(() -> { // reference class
 607             Void r = (Void) vh.getAndSetAcquire(recv, "foo");
 608         });
 609         checkWMTE(() -> { // primitive class
 610             boolean x = (boolean) vh.getAndSetAcquire(recv, "foo");
 611         });
 612         // Incorrect arity
 613         checkWMTE(() -> { // 0
 614             String x = (String) vh.getAndSetAcquire();
 615         });
 616         checkWMTE(() -> { // >
 617             String x = (String) vh.getAndSetAcquire(recv, "foo", Void.class);
 618         });
 619 
 620         // GetAndSetRelease
 621         // Incorrect argument types
 622         checkNPE(() -> { // null receiver
 623             String x = (String) vh.getAndSetRelease(null, "foo");
 624         });
 625         checkCCE(() -> { // receiver reference class
 626             String x = (String) vh.getAndSetRelease(Void.class, "foo");
 627         });
 628         checkCCE(() -> { // value reference class
 629             String x = (String) vh.getAndSetRelease(recv, Void.class);
 630         });
 631         checkWMTE(() -> { // reciever primitive class
 632             String x = (String) vh.getAndSetRelease(0, "foo");
 633         });
 634         // Incorrect return type
 635         checkCCE(() -> { // reference class
 636             Void r = (Void) vh.getAndSetRelease(recv, "foo");
 637         });
 638         checkWMTE(() -> { // primitive class
 639             boolean x = (boolean) vh.getAndSetRelease(recv, "foo");
 640         });
 641         // Incorrect arity
 642         checkWMTE(() -> { // 0
 643             String x = (String) vh.getAndSetRelease();
 644         });
 645         checkWMTE(() -> { // >
 646             String x = (String) vh.getAndSetRelease(recv, "foo", Void.class);
 647         });
 648 
 649 
 650     }
 651 
 652     static void testInstanceFieldWrongMethodType(VarHandleTestMethodTypeString recv, Handles hs) throws Throwable {
 653         for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET)) {
 654             // Incorrect argument types
 655             checkNPE(() -> { // null receiver
 656                 String x = (String) hs.get(am, methodType(type, VarHandleTestMethodTypeString.class)).
 657                     invokeExact((VarHandleTestMethodTypeString) null);
 658             });
 659             hs.checkWMTEOrCCE(() -> { // receiver reference class
 660                 String x = (String) hs.get(am, methodType(type, Class.class)).
 661                     invokeExact(Void.class);
 662             });
 663             checkWMTE(() -> { // receiver primitive class
 664                 String x = (String) hs.get(am, methodType(type, 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, VarHandleTestMethodTypeString.class)).
 670                     invokeExact(recv);
 671             });
 672             checkWMTE(() -> { // primitive class
 673                 boolean x = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeString.class)).
 674                     invokeExact(recv);
 675             });
 676             // Incorrect arity
 677             checkWMTE(() -> { // 0
 678                 String x = (String) hs.get(am, methodType(type)).
 679                     invokeExact();
 680             });
 681             checkWMTE(() -> { // >
 682                 String x = (String) hs.get(am, methodType(type, VarHandleTestMethodTypeString.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, VarHandleTestMethodTypeString.class, type)).
 691                     invokeExact((VarHandleTestMethodTypeString) null, "foo");
 692             });
 693             hs.checkWMTEOrCCE(() -> { // receiver reference class
 694                 hs.get(am, methodType(void.class, Class.class, type)).
 695                     invokeExact(Void.class, "foo");
 696             });
 697             hs.checkWMTEOrCCE(() -> { // value reference class
 698                 hs.get(am, methodType(void.class, VarHandleTestMethodTypeString.class, Class.class)).
 699                     invokeExact(recv, Void.class);
 700             });
 701             checkWMTE(() -> { // receiver primitive class
 702                 hs.get(am, methodType(void.class, int.class, type)).
 703                     invokeExact(0, "foo");
 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, VarHandleTestMethodTypeString.class, type, Class.class)).
 712                     invokeExact(recv, "foo", 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, VarHandleTestMethodTypeString.class, type, type)).
 720                     invokeExact((VarHandleTestMethodTypeString) null, "foo", "foo");
 721             });
 722             hs.checkWMTEOrCCE(() -> { // receiver reference class
 723                 boolean r = (boolean) hs.get(am, methodType(boolean.class, Class.class, type, type)).
 724                     invokeExact(Void.class, "foo", "foo");
 725             });
 726             hs.checkWMTEOrCCE(() -> { // expected reference class
 727                 boolean r = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeString.class, Class.class, type)).
 728                     invokeExact(recv, Void.class, "foo");
 729             });
 730             hs.checkWMTEOrCCE(() -> { // actual reference class
 731                 boolean r = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeString.class, type, Class.class)).
 732                     invokeExact(recv, "foo", Void.class);
 733             });
 734             checkWMTE(() -> { // receiver primitive class
 735                 boolean r = (boolean) hs.get(am, methodType(boolean.class, int.class , type, type)).
 736                     invokeExact(0, "foo", "foo");
 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, VarHandleTestMethodTypeString.class, type, type, Class.class)).
 745                     invokeExact(recv, "foo", "foo", Void.class);
 746             });
 747         }
 748 
 749         for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
 750             checkNPE(() -> { // null receiver
 751                 String x = (String) hs.get(am, methodType(type, VarHandleTestMethodTypeString.class, type, type)).
 752                     invokeExact((VarHandleTestMethodTypeString) null, "foo", "foo");
 753             });
 754             hs.checkWMTEOrCCE(() -> { // receiver reference class
 755                 String x = (String) hs.get(am, methodType(type, Class.class, type, type)).
 756                     invokeExact(Void.class, "foo", "foo");
 757             });
 758             hs.checkWMTEOrCCE(() -> { // expected reference class
 759                 String x = (String) hs.get(am, methodType(type, VarHandleTestMethodTypeString.class, Class.class, type)).
 760                     invokeExact(recv, Void.class, "foo");
 761             });
 762             hs.checkWMTEOrCCE(() -> { // actual reference class
 763                 String x = (String) hs.get(am, methodType(type, VarHandleTestMethodTypeString.class, type, Class.class)).
 764                     invokeExact(recv, "foo", Void.class);
 765             });
 766             checkWMTE(() -> { // reciever primitive class
 767                 String x = (String) hs.get(am, methodType(type, int.class , type, type)).
 768                     invokeExact(0, "foo", "foo");
 769             });
 770             // Incorrect return type
 771             hs.checkWMTEOrCCE(() -> { // reference class
 772                 Void r = (Void) hs.get(am, methodType(Void.class, VarHandleTestMethodTypeString.class , type, type)).
 773                     invokeExact(recv, "foo", "foo");
 774             });
 775             checkWMTE(() -> { // primitive class
 776                 boolean x = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeString.class , type, type)).
 777                     invokeExact(recv, "foo", "foo");
 778             });
 779             // Incorrect arity
 780             checkWMTE(() -> { // 0
 781                 String x = (String) hs.get(am, methodType(type)).
 782                     invokeExact();
 783             });
 784             checkWMTE(() -> { // >
 785                 String x = (String) hs.get(am, methodType(type, VarHandleTestMethodTypeString.class, type, type, Class.class)).
 786                     invokeExact(recv, "foo", "foo", Void.class);
 787             });
 788         }
 789 
 790         for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
 791             checkNPE(() -> { // null receiver
 792                 String x = (String) hs.get(am, methodType(type, VarHandleTestMethodTypeString.class, type)).
 793                     invokeExact((VarHandleTestMethodTypeString) null, "foo");
 794             });
 795             hs.checkWMTEOrCCE(() -> { // receiver reference class
 796                 String x = (String) hs.get(am, methodType(type, Class.class, type)).
 797                     invokeExact(Void.class, "foo");
 798             });
 799             hs.checkWMTEOrCCE(() -> { // value reference class
 800                 String x = (String) hs.get(am, methodType(type, VarHandleTestMethodTypeString.class, Class.class)).
 801                     invokeExact(recv, Void.class);
 802             });
 803             checkWMTE(() -> { // reciever primitive class
 804                 String x = (String) hs.get(am, methodType(type, int.class, type)).
 805                     invokeExact(0, "foo");
 806             });
 807             // Incorrect return type
 808             hs.checkWMTEOrCCE(() -> { // reference class
 809                 Void r = (Void) hs.get(am, methodType(Void.class, VarHandleTestMethodTypeString.class, type)).
 810                     invokeExact(recv, "foo");
 811             });
 812             checkWMTE(() -> { // primitive class
 813                 boolean x = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeString.class, type)).
 814                     invokeExact(recv, "foo");
 815             });
 816             // Incorrect arity
 817             checkWMTE(() -> { // 0
 818                 String x = (String) hs.get(am, methodType(type)).
 819                     invokeExact();
 820             });
 821             checkWMTE(() -> { // >
 822                 String x = (String) hs.get(am, methodType(type, VarHandleTestMethodTypeString.class, type)).
 823                     invokeExact(recv, "foo", 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             String x = (String) 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("foo", 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             String x = (String) 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("foo", 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             String x = (String) 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("foo", 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             String x = (String) 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("foo", Void.class);
 938         });
 939 
 940 
 941         // CompareAndSet
 942         // Incorrect argument types
 943         checkCCE(() -> { // expected reference class
 944             boolean r = vh.compareAndSet(Void.class, "foo");
 945         });
 946         checkCCE(() -> { // actual reference class
 947             boolean r = vh.compareAndSet("foo", Void.class);
 948         });
 949         // Incorrect arity
 950         checkWMTE(() -> { // 0
 951             boolean r = vh.compareAndSet();
 952         });
 953         checkWMTE(() -> { // >
 954             boolean r = vh.compareAndSet("foo", "foo", Void.class);
 955         });
 956 
 957 
 958         // WeakCompareAndSet
 959         // Incorrect argument types
 960         checkCCE(() -> { // expected reference class
 961             boolean r = vh.weakCompareAndSetPlain(Void.class, "foo");
 962         });
 963         checkCCE(() -> { // actual reference class
 964             boolean r = vh.weakCompareAndSetPlain("foo", Void.class);
 965         });
 966         // Incorrect arity
 967         checkWMTE(() -> { // 0
 968             boolean r = vh.weakCompareAndSetPlain();
 969         });
 970         checkWMTE(() -> { // >
 971             boolean r = vh.weakCompareAndSetPlain("foo", "foo", Void.class);
 972         });
 973 
 974 
 975         // WeakCompareAndSetVolatile
 976         // Incorrect argument types
 977         checkCCE(() -> { // expected reference class
 978             boolean r = vh.weakCompareAndSet(Void.class, "foo");
 979         });
 980         checkCCE(() -> { // actual reference class
 981             boolean r = vh.weakCompareAndSet("foo", Void.class);
 982         });
 983         // Incorrect arity
 984         checkWMTE(() -> { // 0
 985             boolean r = vh.weakCompareAndSet();
 986         });
 987         checkWMTE(() -> { // >
 988             boolean r = vh.weakCompareAndSet("foo", "foo", Void.class);
 989         });
 990 
 991 
 992         // WeakCompareAndSetAcquire
 993         // Incorrect argument types
 994         checkCCE(() -> { // expected reference class
 995             boolean r = vh.weakCompareAndSetAcquire(Void.class, "foo");
 996         });
 997         checkCCE(() -> { // actual reference class
 998             boolean r = vh.weakCompareAndSetAcquire("foo", Void.class);
 999         });
1000         // Incorrect arity
1001         checkWMTE(() -> { // 0
1002             boolean r = vh.weakCompareAndSetAcquire();
1003         });
1004         checkWMTE(() -> { // >
1005             boolean r = vh.weakCompareAndSetAcquire("foo", "foo", Void.class);
1006         });
1007 
1008 
1009         // WeakCompareAndSetRelease
1010         // Incorrect argument types
1011         checkCCE(() -> { // expected reference class
1012             boolean r = vh.weakCompareAndSetRelease(Void.class, "foo");
1013         });
1014         checkCCE(() -> { // actual reference class
1015             boolean r = vh.weakCompareAndSetRelease("foo", Void.class);
1016         });
1017         // Incorrect arity
1018         checkWMTE(() -> { // 0
1019             boolean r = vh.weakCompareAndSetRelease();
1020         });
1021         checkWMTE(() -> { // >
1022             boolean r = vh.weakCompareAndSetRelease("foo", "foo", Void.class);
1023         });
1024 
1025 
1026         // CompareAndExchange
1027         // Incorrect argument types
1028         checkCCE(() -> { // expected reference class
1029             String x = (String) vh.compareAndExchange(Void.class, "foo");
1030         });
1031         checkCCE(() -> { // actual reference class
1032             String x = (String) vh.compareAndExchange("foo", Void.class);
1033         });
1034         // Incorrect return type
1035         checkCCE(() -> { // reference class
1036             Void r = (Void) vh.compareAndExchange("foo", "foo");
1037         });
1038         checkWMTE(() -> { // primitive class
1039             boolean x = (boolean) vh.compareAndExchange("foo", "foo");
1040         });
1041         // Incorrect arity
1042         checkWMTE(() -> { // 0
1043             String x = (String) vh.compareAndExchange();
1044         });
1045         checkWMTE(() -> { // >
1046             String x = (String) vh.compareAndExchange("foo", "foo", Void.class);
1047         });
1048 
1049 
1050         // CompareAndExchangeAcquire
1051         // Incorrect argument types
1052         checkCCE(() -> { // expected reference class
1053             String x = (String) vh.compareAndExchangeAcquire(Void.class, "foo");
1054         });
1055         checkCCE(() -> { // actual reference class
1056             String x = (String) vh.compareAndExchangeAcquire("foo", Void.class);
1057         });
1058         // Incorrect return type
1059         checkCCE(() -> { // reference class
1060             Void r = (Void) vh.compareAndExchangeAcquire("foo", "foo");
1061         });
1062         checkWMTE(() -> { // primitive class
1063             boolean x = (boolean) vh.compareAndExchangeAcquire("foo", "foo");
1064         });
1065         // Incorrect arity
1066         checkWMTE(() -> { // 0
1067             String x = (String) vh.compareAndExchangeAcquire();
1068         });
1069         checkWMTE(() -> { // >
1070             String x = (String) vh.compareAndExchangeAcquire("foo", "foo", Void.class);
1071         });
1072 
1073 
1074         // CompareAndExchangeRelease
1075         // Incorrect argument types
1076         checkCCE(() -> { // expected reference class
1077             String x = (String) vh.compareAndExchangeRelease(Void.class, "foo");
1078         });
1079         checkCCE(() -> { // actual reference class
1080             String x = (String) vh.compareAndExchangeRelease("foo", Void.class);
1081         });
1082         // Incorrect return type
1083         checkCCE(() -> { // reference class
1084             Void r = (Void) vh.compareAndExchangeRelease("foo", "foo");
1085         });
1086         checkWMTE(() -> { // primitive class
1087             boolean x = (boolean) vh.compareAndExchangeRelease("foo", "foo");
1088         });
1089         // Incorrect arity
1090         checkWMTE(() -> { // 0
1091             String x = (String) vh.compareAndExchangeRelease();
1092         });
1093         checkWMTE(() -> { // >
1094             String x = (String) vh.compareAndExchangeRelease("foo", "foo", Void.class);
1095         });
1096 
1097 
1098         // GetAndSet
1099         // Incorrect argument types
1100         checkCCE(() -> { // value reference class
1101             String x = (String) vh.getAndSet(Void.class);
1102         });
1103         // Incorrect return type
1104         checkCCE(() -> { // reference class
1105             Void r = (Void) vh.getAndSet("foo");
1106         });
1107         checkWMTE(() -> { // primitive class
1108             boolean x = (boolean) vh.getAndSet("foo");
1109         });
1110         // Incorrect arity
1111         checkWMTE(() -> { // 0
1112             String x = (String) vh.getAndSet();
1113         });
1114         checkWMTE(() -> { // >
1115             String x = (String) vh.getAndSet("foo", Void.class);
1116         });
1117 
1118 
1119         // GetAndSetAcquire
1120         // Incorrect argument types
1121         checkCCE(() -> { // value reference class
1122             String x = (String) vh.getAndSetAcquire(Void.class);
1123         });
1124         // Incorrect return type
1125         checkCCE(() -> { // reference class
1126             Void r = (Void) vh.getAndSetAcquire("foo");
1127         });
1128         checkWMTE(() -> { // primitive class
1129             boolean x = (boolean) vh.getAndSetAcquire("foo");
1130         });
1131         // Incorrect arity
1132         checkWMTE(() -> { // 0
1133             String x = (String) vh.getAndSetAcquire();
1134         });
1135         checkWMTE(() -> { // >
1136             String x = (String) vh.getAndSetAcquire("foo", Void.class);
1137         });
1138 
1139 
1140         // GetAndSetRelease
1141         // Incorrect argument types
1142         checkCCE(() -> { // value reference class
1143             String x = (String) vh.getAndSetRelease(Void.class);
1144         });
1145         // Incorrect return type
1146         checkCCE(() -> { // reference class
1147             Void r = (Void) vh.getAndSetRelease("foo");
1148         });
1149         checkWMTE(() -> { // primitive class
1150             boolean x = (boolean) vh.getAndSetRelease("foo");
1151         });
1152         // Incorrect arity
1153         checkWMTE(() -> { // 0
1154             String x = (String) vh.getAndSetRelease();
1155         });
1156         checkWMTE(() -> { // >
1157             String x = (String) vh.getAndSetRelease("foo", 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                 String x = (String) 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, type, Class.class)).
1195                     invokeExact("foo", 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, type)).
1202                     invokeExact(Void.class, "foo");
1203             });
1204             hs.checkWMTEOrCCE(() -> { // actual reference class
1205                 boolean r = (boolean) hs.get(am, methodType(boolean.class, type, Class.class)).
1206                     invokeExact("foo", 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, type, type, Class.class)).
1215                     invokeExact("foo", "foo", 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                 String x = (String) hs.get(am, methodType(type, Class.class, type)).
1223                     invokeExact(Void.class, "foo");
1224             });
1225             hs.checkWMTEOrCCE(() -> { // actual reference class
1226                 String x = (String) hs.get(am, methodType(type, type, Class.class)).
1227                     invokeExact("foo", Void.class);
1228             });
1229             // Incorrect return type
1230             hs.checkWMTEOrCCE(() -> { // reference class
1231                 Void r = (Void) hs.get(am, methodType(Void.class, type, type)).
1232                     invokeExact("foo", "foo");
1233             });
1234             checkWMTE(() -> { // primitive class
1235                 boolean x = (boolean) hs.get(am, methodType(boolean.class, type, type)).
1236                     invokeExact("foo", "foo");
1237             });
1238             // Incorrect arity
1239             checkWMTE(() -> { // 0
1240                 String x = (String) hs.get(am, methodType(type)).
1241                     invokeExact();
1242             });
1243             checkWMTE(() -> { // >
1244                 String x = (String) hs.get(am, methodType(type, type, type, Class.class)).
1245                     invokeExact("foo", "foo", 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                 String x = (String) hs.get(am, methodType(type, 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, type)).
1258                     invokeExact("foo");
1259             });
1260             checkWMTE(() -> { // primitive class
1261                 boolean x = (boolean) hs.get(am, methodType(boolean.class, type)).
1262                     invokeExact("foo");
1263             });
1264             // Incorrect arity
1265             checkWMTE(() -> { // 0
1266                 String x = (String) hs.get(am, methodType(type)).
1267                     invokeExact();
1268             });
1269             checkWMTE(() -> { // >
1270                 String x = (String) hs.get(am, methodType(type, type, Class.class)).
1271                     invokeExact("foo", Void.class);
1272             });
1273         }
1274 
1275 
1276     }
1277 
1278 
1279     static void testArrayWrongMethodType(VarHandle vh) throws Throwable {
1280         String[] array = new String[10];
1281         Arrays.fill(array, "foo");
1282 
1283         // Get
1284         // Incorrect argument types
1285         checkNPE(() -> { // null array
1286             String x = (String) vh.get(null, 0);
1287         });
1288         checkCCE(() -> { // array reference class
1289             String x = (String) vh.get(Void.class, 0);
1290         });
1291         checkWMTE(() -> { // array primitive class
1292             String x = (String) vh.get(0, 0);
1293         });
1294         checkWMTE(() -> { // index reference class
1295             String x = (String) 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             String x = (String) vh.get();
1307         });
1308         checkWMTE(() -> { // >
1309             String x = (String) vh.get(array, 0, Void.class);
1310         });
1311 
1312 
1313         // Set
1314         // Incorrect argument types
1315         checkNPE(() -> { // null array
1316             vh.set(null, 0, "foo");
1317         });
1318         checkCCE(() -> { // array reference class
1319             vh.set(Void.class, 0, "foo");
1320         });
1321         checkCCE(() -> { // value reference class
1322             vh.set(array, 0, Void.class);
1323         });
1324         checkWMTE(() -> { // receiver primitive class
1325             vh.set(0, 0, "foo");
1326         });
1327         checkWMTE(() -> { // index reference class
1328             vh.set(array, Void.class, "foo");
1329         });
1330         // Incorrect arity
1331         checkWMTE(() -> { // 0
1332             vh.set();
1333         });
1334         checkWMTE(() -> { // >
1335             vh.set(array, 0, "foo", Void.class);
1336         });
1337 
1338 
1339         // GetVolatile
1340         // Incorrect argument types
1341         checkNPE(() -> { // null array
1342             String x = (String) vh.getVolatile(null, 0);
1343         });
1344         checkCCE(() -> { // array reference class
1345             String x = (String) vh.getVolatile(Void.class, 0);
1346         });
1347         checkWMTE(() -> { // array primitive class
1348             String x = (String) vh.getVolatile(0, 0);
1349         });
1350         checkWMTE(() -> { // index reference class
1351             String x = (String) 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             String x = (String) vh.getVolatile();
1363         });
1364         checkWMTE(() -> { // >
1365             String x = (String) vh.getVolatile(array, 0, Void.class);
1366         });
1367 
1368 
1369         // SetVolatile
1370         // Incorrect argument types
1371         checkNPE(() -> { // null array
1372             vh.setVolatile(null, 0, "foo");
1373         });
1374         checkCCE(() -> { // array reference class
1375             vh.setVolatile(Void.class, 0, "foo");
1376         });
1377         checkCCE(() -> { // value reference class
1378             vh.setVolatile(array, 0, Void.class);
1379         });
1380         checkWMTE(() -> { // receiver primitive class
1381             vh.setVolatile(0, 0, "foo");
1382         });
1383         checkWMTE(() -> { // index reference class
1384             vh.setVolatile(array, Void.class, "foo");
1385         });
1386         // Incorrect arity
1387         checkWMTE(() -> { // 0
1388             vh.setVolatile();
1389         });
1390         checkWMTE(() -> { // >
1391             vh.setVolatile(array, 0, "foo", Void.class);
1392         });
1393 
1394 
1395         // GetOpaque
1396         // Incorrect argument types
1397         checkNPE(() -> { // null array
1398             String x = (String) vh.getOpaque(null, 0);
1399         });
1400         checkCCE(() -> { // array reference class
1401             String x = (String) vh.getOpaque(Void.class, 0);
1402         });
1403         checkWMTE(() -> { // array primitive class
1404             String x = (String) vh.getOpaque(0, 0);
1405         });
1406         checkWMTE(() -> { // index reference class
1407             String x = (String) 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             String x = (String) vh.getOpaque();
1419         });
1420         checkWMTE(() -> { // >
1421             String x = (String) vh.getOpaque(array, 0, Void.class);
1422         });
1423 
1424 
1425         // SetOpaque
1426         // Incorrect argument types
1427         checkNPE(() -> { // null array
1428             vh.setOpaque(null, 0, "foo");
1429         });
1430         checkCCE(() -> { // array reference class
1431             vh.setOpaque(Void.class, 0, "foo");
1432         });
1433         checkCCE(() -> { // value reference class
1434             vh.setOpaque(array, 0, Void.class);
1435         });
1436         checkWMTE(() -> { // receiver primitive class
1437             vh.setOpaque(0, 0, "foo");
1438         });
1439         checkWMTE(() -> { // index reference class
1440             vh.setOpaque(array, Void.class, "foo");
1441         });
1442         // Incorrect arity
1443         checkWMTE(() -> { // 0
1444             vh.setOpaque();
1445         });
1446         checkWMTE(() -> { // >
1447             vh.setOpaque(array, 0, "foo", Void.class);
1448         });
1449 
1450 
1451         // GetAcquire
1452         // Incorrect argument types
1453         checkNPE(() -> { // null array
1454             String x = (String) vh.getAcquire(null, 0);
1455         });
1456         checkCCE(() -> { // array reference class
1457             String x = (String) vh.getAcquire(Void.class, 0);
1458         });
1459         checkWMTE(() -> { // array primitive class
1460             String x = (String) vh.getAcquire(0, 0);
1461         });
1462         checkWMTE(() -> { // index reference class
1463             String x = (String) 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             String x = (String) vh.getAcquire();
1475         });
1476         checkWMTE(() -> { // >
1477             String x = (String) vh.getAcquire(array, 0, Void.class);
1478         });
1479 
1480 
1481         // SetRelease
1482         // Incorrect argument types
1483         checkNPE(() -> { // null array
1484             vh.setRelease(null, 0, "foo");
1485         });
1486         checkCCE(() -> { // array reference class
1487             vh.setRelease(Void.class, 0, "foo");
1488         });
1489         checkCCE(() -> { // value reference class
1490             vh.setRelease(array, 0, Void.class);
1491         });
1492         checkWMTE(() -> { // receiver primitive class
1493             vh.setRelease(0, 0, "foo");
1494         });
1495         checkWMTE(() -> { // index reference class
1496             vh.setRelease(array, Void.class, "foo");
1497         });
1498         // Incorrect arity
1499         checkWMTE(() -> { // 0
1500             vh.setRelease();
1501         });
1502         checkWMTE(() -> { // >
1503             vh.setRelease(array, 0, "foo", Void.class);
1504         });
1505 
1506 
1507         // CompareAndSet
1508         // Incorrect argument types
1509         checkNPE(() -> { // null receiver
1510             boolean r = vh.compareAndSet(null, 0, "foo", "foo");
1511         });
1512         checkCCE(() -> { // receiver reference class
1513             boolean r = vh.compareAndSet(Void.class, 0, "foo", "foo");
1514         });
1515         checkCCE(() -> { // expected reference class
1516             boolean r = vh.compareAndSet(array, 0, Void.class, "foo");
1517         });
1518         checkCCE(() -> { // actual reference class
1519             boolean r = vh.compareAndSet(array, 0, "foo", Void.class);
1520         });
1521         checkWMTE(() -> { // receiver primitive class
1522             boolean r = vh.compareAndSet(0, 0, "foo", "foo");
1523         });
1524         checkWMTE(() -> { // index reference class
1525             boolean r = vh.compareAndSet(array, Void.class, "foo", "foo");
1526         });
1527         // Incorrect arity
1528         checkWMTE(() -> { // 0
1529             boolean r = vh.compareAndSet();
1530         });
1531         checkWMTE(() -> { // >
1532             boolean r = vh.compareAndSet(array, 0, "foo", "foo", Void.class);
1533         });
1534 
1535 
1536         // WeakCompareAndSet
1537         // Incorrect argument types
1538         checkNPE(() -> { // null receiver
1539             boolean r = vh.weakCompareAndSetPlain(null, 0, "foo", "foo");
1540         });
1541         checkCCE(() -> { // receiver reference class
1542             boolean r = vh.weakCompareAndSetPlain(Void.class, 0, "foo", "foo");
1543         });
1544         checkCCE(() -> { // expected reference class
1545             boolean r = vh.weakCompareAndSetPlain(array, 0, Void.class, "foo");
1546         });
1547         checkCCE(() -> { // actual reference class
1548             boolean r = vh.weakCompareAndSetPlain(array, 0, "foo", Void.class);
1549         });
1550         checkWMTE(() -> { // receiver primitive class
1551             boolean r = vh.weakCompareAndSetPlain(0, 0, "foo", "foo");
1552         });
1553         checkWMTE(() -> { // index reference class
1554             boolean r = vh.weakCompareAndSetPlain(array, Void.class, "foo", "foo");
1555         });
1556         // Incorrect arity
1557         checkWMTE(() -> { // 0
1558             boolean r = vh.weakCompareAndSetPlain();
1559         });
1560         checkWMTE(() -> { // >
1561             boolean r = vh.weakCompareAndSetPlain(array, 0, "foo", "foo", Void.class);
1562         });
1563 
1564 
1565         // WeakCompareAndSetVolatile
1566         // Incorrect argument types
1567         checkNPE(() -> { // null receiver
1568             boolean r = vh.weakCompareAndSet(null, 0, "foo", "foo");
1569         });
1570         checkCCE(() -> { // receiver reference class
1571             boolean r = vh.weakCompareAndSet(Void.class, 0, "foo", "foo");
1572         });
1573         checkCCE(() -> { // expected reference class
1574             boolean r = vh.weakCompareAndSet(array, 0, Void.class, "foo");
1575         });
1576         checkCCE(() -> { // actual reference class
1577             boolean r = vh.weakCompareAndSet(array, 0, "foo", Void.class);
1578         });
1579         checkWMTE(() -> { // receiver primitive class
1580             boolean r = vh.weakCompareAndSet(0, 0, "foo", "foo");
1581         });
1582         checkWMTE(() -> { // index reference class
1583             boolean r = vh.weakCompareAndSet(array, Void.class, "foo", "foo");
1584         });
1585         // Incorrect arity
1586         checkWMTE(() -> { // 0
1587             boolean r = vh.weakCompareAndSet();
1588         });
1589         checkWMTE(() -> { // >
1590             boolean r = vh.weakCompareAndSet(array, 0, "foo", "foo", Void.class);
1591         });
1592 
1593 
1594         // WeakCompareAndSetAcquire
1595         // Incorrect argument types
1596         checkNPE(() -> { // null receiver
1597             boolean r = vh.weakCompareAndSetAcquire(null, 0, "foo", "foo");
1598         });
1599         checkCCE(() -> { // receiver reference class
1600             boolean r = vh.weakCompareAndSetAcquire(Void.class, 0, "foo", "foo");
1601         });
1602         checkCCE(() -> { // expected reference class
1603             boolean r = vh.weakCompareAndSetAcquire(array, 0, Void.class, "foo");
1604         });
1605         checkCCE(() -> { // actual reference class
1606             boolean r = vh.weakCompareAndSetAcquire(array, 0, "foo", Void.class);
1607         });
1608         checkWMTE(() -> { // receiver primitive class
1609             boolean r = vh.weakCompareAndSetAcquire(0, 0, "foo", "foo");
1610         });
1611         checkWMTE(() -> { // index reference class
1612             boolean r = vh.weakCompareAndSetAcquire(array, Void.class, "foo", "foo");
1613         });
1614         // Incorrect arity
1615         checkWMTE(() -> { // 0
1616             boolean r = vh.weakCompareAndSetAcquire();
1617         });
1618         checkWMTE(() -> { // >
1619             boolean r = vh.weakCompareAndSetAcquire(array, 0, "foo", "foo", Void.class);
1620         });
1621 
1622 
1623         // WeakCompareAndSetRelease
1624         // Incorrect argument types
1625         checkNPE(() -> { // null receiver
1626             boolean r = vh.weakCompareAndSetRelease(null, 0, "foo", "foo");
1627         });
1628         checkCCE(() -> { // receiver reference class
1629             boolean r = vh.weakCompareAndSetRelease(Void.class, 0, "foo", "foo");
1630         });
1631         checkCCE(() -> { // expected reference class
1632             boolean r = vh.weakCompareAndSetRelease(array, 0, Void.class, "foo");
1633         });
1634         checkCCE(() -> { // actual reference class
1635             boolean r = vh.weakCompareAndSetRelease(array, 0, "foo", Void.class);
1636         });
1637         checkWMTE(() -> { // receiver primitive class
1638             boolean r = vh.weakCompareAndSetRelease(0, 0, "foo", "foo");
1639         });
1640         checkWMTE(() -> { // index reference class
1641             boolean r = vh.weakCompareAndSetRelease(array, Void.class, "foo", "foo");
1642         });
1643         // Incorrect arity
1644         checkWMTE(() -> { // 0
1645             boolean r = vh.weakCompareAndSetRelease();
1646         });
1647         checkWMTE(() -> { // >
1648             boolean r = vh.weakCompareAndSetRelease(array, 0, "foo", "foo", Void.class);
1649         });
1650 
1651 
1652         // CompareAndExchange
1653         // Incorrect argument types
1654         checkNPE(() -> { // null receiver
1655             String x = (String) vh.compareAndExchange(null, 0, "foo", "foo");
1656         });
1657         checkCCE(() -> { // array reference class
1658             String x = (String) vh.compareAndExchange(Void.class, 0, "foo", "foo");
1659         });
1660         checkCCE(() -> { // expected reference class
1661             String x = (String) vh.compareAndExchange(array, 0, Void.class, "foo");
1662         });
1663         checkCCE(() -> { // actual reference class
1664             String x = (String) vh.compareAndExchange(array, 0, "foo", Void.class);
1665         });
1666         checkWMTE(() -> { // array primitive class
1667             String x = (String) vh.compareAndExchange(0, 0, "foo", "foo");
1668         });
1669         checkWMTE(() -> { // index reference class
1670             String x = (String) vh.compareAndExchange(array, Void.class, "foo", "foo");
1671         });
1672         // Incorrect return type
1673         checkCCE(() -> { // reference class
1674             Void r = (Void) vh.compareAndExchange(array, 0, "foo", "foo");
1675         });
1676         checkWMTE(() -> { // primitive class
1677             boolean x = (boolean) vh.compareAndExchange(array, 0, "foo", "foo");
1678         });
1679         // Incorrect arity
1680         checkWMTE(() -> { // 0
1681             String x = (String) vh.compareAndExchange();
1682         });
1683         checkWMTE(() -> { // >
1684             String x = (String) vh.compareAndExchange(array, 0, "foo", "foo", Void.class);
1685         });
1686 
1687 
1688         // CompareAndExchangeAcquire
1689         // Incorrect argument types
1690         checkNPE(() -> { // null receiver
1691             String x = (String) vh.compareAndExchangeAcquire(null, 0, "foo", "foo");
1692         });
1693         checkCCE(() -> { // array reference class
1694             String x = (String) vh.compareAndExchangeAcquire(Void.class, 0, "foo", "foo");
1695         });
1696         checkCCE(() -> { // expected reference class
1697             String x = (String) vh.compareAndExchangeAcquire(array, 0, Void.class, "foo");
1698         });
1699         checkCCE(() -> { // actual reference class
1700             String x = (String) vh.compareAndExchangeAcquire(array, 0, "foo", Void.class);
1701         });
1702         checkWMTE(() -> { // array primitive class
1703             String x = (String) vh.compareAndExchangeAcquire(0, 0, "foo", "foo");
1704         });
1705         checkWMTE(() -> { // index reference class
1706             String x = (String) vh.compareAndExchangeAcquire(array, Void.class, "foo", "foo");
1707         });
1708         // Incorrect return type
1709         checkCCE(() -> { // reference class
1710             Void r = (Void) vh.compareAndExchangeAcquire(array, 0, "foo", "foo");
1711         });
1712         checkWMTE(() -> { // primitive class
1713             boolean x = (boolean) vh.compareAndExchangeAcquire(array, 0, "foo", "foo");
1714         });
1715         // Incorrect arity
1716         checkWMTE(() -> { // 0
1717             String x = (String) vh.compareAndExchangeAcquire();
1718         });
1719         checkWMTE(() -> { // >
1720             String x = (String) vh.compareAndExchangeAcquire(array, 0, "foo", "foo", Void.class);
1721         });
1722 
1723 
1724         // CompareAndExchangeRelease
1725         // Incorrect argument types
1726         checkNPE(() -> { // null receiver
1727             String x = (String) vh.compareAndExchangeRelease(null, 0, "foo", "foo");
1728         });
1729         checkCCE(() -> { // array reference class
1730             String x = (String) vh.compareAndExchangeRelease(Void.class, 0, "foo", "foo");
1731         });
1732         checkCCE(() -> { // expected reference class
1733             String x = (String) vh.compareAndExchangeRelease(array, 0, Void.class, "foo");
1734         });
1735         checkCCE(() -> { // actual reference class
1736             String x = (String) vh.compareAndExchangeRelease(array, 0, "foo", Void.class);
1737         });
1738         checkWMTE(() -> { // array primitive class
1739             String x = (String) vh.compareAndExchangeRelease(0, 0, "foo", "foo");
1740         });
1741         checkWMTE(() -> { // index reference class
1742             String x = (String) vh.compareAndExchangeRelease(array, Void.class, "foo", "foo");
1743         });
1744         // Incorrect return type
1745         checkCCE(() -> { // reference class
1746             Void r = (Void) vh.compareAndExchangeRelease(array, 0, "foo", "foo");
1747         });
1748         checkWMTE(() -> { // primitive class
1749             boolean x = (boolean) vh.compareAndExchangeRelease(array, 0, "foo", "foo");
1750         });
1751         // Incorrect arity
1752         checkWMTE(() -> { // 0
1753             String x = (String) vh.compareAndExchangeRelease();
1754         });
1755         checkWMTE(() -> { // >
1756             String x = (String) vh.compareAndExchangeRelease(array, 0, "foo", "foo", Void.class);
1757         });
1758 
1759 
1760         // GetAndSet
1761         // Incorrect argument types
1762         checkNPE(() -> { // null array
1763             String x = (String) vh.getAndSet(null, 0, "foo");
1764         });
1765         checkCCE(() -> { // array reference class
1766             String x = (String) vh.getAndSet(Void.class, 0, "foo");
1767         });
1768         checkCCE(() -> { // value reference class
1769             String x = (String) vh.getAndSet(array, 0, Void.class);
1770         });
1771         checkWMTE(() -> { // reciarrayever primitive class
1772             String x = (String) vh.getAndSet(0, 0, "foo");
1773         });
1774         checkWMTE(() -> { // index reference class
1775             String x = (String) vh.getAndSet(array, Void.class, "foo");
1776         });
1777         // Incorrect return type
1778         checkCCE(() -> { // reference class
1779             Void r = (Void) vh.getAndSet(array, 0, "foo");
1780         });
1781         checkWMTE(() -> { // primitive class
1782             boolean x = (boolean) vh.getAndSet(array, 0, "foo");
1783         });
1784         // Incorrect arity
1785         checkWMTE(() -> { // 0
1786             String x = (String) vh.getAndSet();
1787         });
1788         checkWMTE(() -> { // >
1789             String x = (String) vh.getAndSet(array, 0, "foo", Void.class);
1790         });
1791 
1792 
1793         // GetAndSetAcquire
1794         // Incorrect argument types
1795         checkNPE(() -> { // null array
1796             String x = (String) vh.getAndSetAcquire(null, 0, "foo");
1797         });
1798         checkCCE(() -> { // array reference class
1799             String x = (String) vh.getAndSetAcquire(Void.class, 0, "foo");
1800         });
1801         checkCCE(() -> { // value reference class
1802             String x = (String) vh.getAndSetAcquire(array, 0, Void.class);
1803         });
1804         checkWMTE(() -> { // reciarrayever primitive class
1805             String x = (String) vh.getAndSetAcquire(0, 0, "foo");
1806         });
1807         checkWMTE(() -> { // index reference class
1808             String x = (String) vh.getAndSetAcquire(array, Void.class, "foo");
1809         });
1810         // Incorrect return type
1811         checkCCE(() -> { // reference class
1812             Void r = (Void) vh.getAndSetAcquire(array, 0, "foo");
1813         });
1814         checkWMTE(() -> { // primitive class
1815             boolean x = (boolean) vh.getAndSetAcquire(array, 0, "foo");
1816         });
1817         // Incorrect arity
1818         checkWMTE(() -> { // 0
1819             String x = (String) vh.getAndSetAcquire();
1820         });
1821         checkWMTE(() -> { // >
1822             String x = (String) vh.getAndSetAcquire(array, 0, "foo", Void.class);
1823         });
1824 
1825 
1826         // GetAndSetRelease
1827         // Incorrect argument types
1828         checkNPE(() -> { // null array
1829             String x = (String) vh.getAndSetRelease(null, 0, "foo");
1830         });
1831         checkCCE(() -> { // array reference class
1832             String x = (String) vh.getAndSetRelease(Void.class, 0, "foo");
1833         });
1834         checkCCE(() -> { // value reference class
1835             String x = (String) vh.getAndSetRelease(array, 0, Void.class);
1836         });
1837         checkWMTE(() -> { // reciarrayever primitive class
1838             String x = (String) vh.getAndSetRelease(0, 0, "foo");
1839         });
1840         checkWMTE(() -> { // index reference class
1841             String x = (String) vh.getAndSetRelease(array, Void.class, "foo");
1842         });
1843         // Incorrect return type
1844         checkCCE(() -> { // reference class
1845             Void r = (Void) vh.getAndSetRelease(array, 0, "foo");
1846         });
1847         checkWMTE(() -> { // primitive class
1848             boolean x = (boolean) vh.getAndSetRelease(array, 0, "foo");
1849         });
1850         // Incorrect arity
1851         checkWMTE(() -> { // 0
1852             String x = (String) vh.getAndSetRelease();
1853         });
1854         checkWMTE(() -> { // >
1855             String x = (String) vh.getAndSetRelease(array, 0, "foo", Void.class);
1856         });
1857 
1858 
1859     }
1860 
1861     static void testArrayWrongMethodType(Handles hs) throws Throwable {
1862         String[] array = new String[10];
1863         Arrays.fill(array, "foo");
1864 
1865         for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET)) {
1866             // Incorrect argument types
1867             checkNPE(() -> { // null array
1868                 String x = (String) hs.get(am, methodType(type, String[].class, int.class)).
1869                     invokeExact((String[]) null, 0);
1870             });
1871             hs.checkWMTEOrCCE(() -> { // array reference class
1872                 String x = (String) hs.get(am, methodType(type, Class.class, int.class)).
1873                     invokeExact(Void.class, 0);
1874             });
1875             checkWMTE(() -> { // array primitive class
1876                 String x = (String) hs.get(am, methodType(type, int.class, int.class)).
1877                     invokeExact(0, 0);
1878             });
1879             checkWMTE(() -> { // index reference class
1880                 String x = (String) hs.get(am, methodType(type, String[].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, String[].class, int.class)).
1886                     invokeExact(array, 0);
1887             });
1888             checkWMTE(() -> { // primitive class
1889                 boolean x = (boolean) hs.get(am, methodType(boolean.class, String[].class, int.class)).
1890                     invokeExact(array, 0);
1891             });
1892             // Incorrect arity
1893             checkWMTE(() -> { // 0
1894                 String x = (String) hs.get(am, methodType(type)).
1895                     invokeExact();
1896             });
1897             checkWMTE(() -> { // >
1898                 String x = (String) hs.get(am, methodType(type, String[].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, String[].class, int.class, type)).
1907                     invokeExact((String[]) null, 0, "foo");
1908             });
1909             hs.checkWMTEOrCCE(() -> { // array reference class
1910                 hs.get(am, methodType(void.class, Class.class, int.class, type)).
1911                     invokeExact(Void.class, 0, "foo");
1912             });
1913             hs.checkWMTEOrCCE(() -> { // value reference class
1914                 hs.get(am, methodType(void.class, String[].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, type)).
1919                     invokeExact(0, 0, "foo");
1920             });
1921             checkWMTE(() -> { // index reference class
1922                 hs.get(am, methodType(void.class, String[].class, Class.class, type)).
1923                     invokeExact(array, Void.class, "foo");
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, String[].class, int.class, Class.class)).
1932                     invokeExact(array, 0, "foo", 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, String[].class, int.class, type, type)).
1939                     invokeExact((String[]) null, 0, "foo", "foo");
1940             });
1941             hs.checkWMTEOrCCE(() -> { // receiver reference class
1942                 boolean r = (boolean) hs.get(am, methodType(boolean.class, Class.class, int.class, type, type)).
1943                     invokeExact(Void.class, 0, "foo", "foo");
1944             });
1945             hs.checkWMTEOrCCE(() -> { // expected reference class
1946                 boolean r = (boolean) hs.get(am, methodType(boolean.class, String[].class, int.class, Class.class, type)).
1947                     invokeExact(array, 0, Void.class, "foo");
1948             });
1949             hs.checkWMTEOrCCE(() -> { // actual reference class
1950                 boolean r = (boolean) hs.get(am, methodType(boolean.class, String[].class, int.class, type, Class.class)).
1951                     invokeExact(array, 0, "foo", Void.class);
1952             });
1953             checkWMTE(() -> { // receiver primitive class
1954                 boolean r = (boolean) hs.get(am, methodType(boolean.class, int.class, int.class, type, type)).
1955                     invokeExact(0, 0, "foo", "foo");
1956             });
1957             checkWMTE(() -> { // index reference class
1958                 boolean r = (boolean) hs.get(am, methodType(boolean.class, String[].class, Class.class, type, type)).
1959                     invokeExact(array, Void.class, "foo", "foo");
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, String[].class, int.class, type, type, Class.class)).
1968                     invokeExact(array, 0, "foo", "foo", Void.class);
1969             });
1970         }
1971 
1972         for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
1973             // Incorrect argument types
1974             checkNPE(() -> { // null receiver
1975                 String x = (String) hs.get(am, methodType(type, String[].class, int.class, type, type)).
1976                     invokeExact((String[]) null, 0, "foo", "foo");
1977             });
1978             hs.checkWMTEOrCCE(() -> { // array reference class
1979                 String x = (String) hs.get(am, methodType(type, Class.class, int.class, type, type)).
1980                     invokeExact(Void.class, 0, "foo", "foo");
1981             });
1982             hs.checkWMTEOrCCE(() -> { // expected reference class
1983                 String x = (String) hs.get(am, methodType(type, String[].class, int.class, Class.class, type)).
1984                     invokeExact(array, 0, Void.class, "foo");
1985             });
1986             hs.checkWMTEOrCCE(() -> { // actual reference class
1987                 String x = (String) hs.get(am, methodType(type, String[].class, int.class, type, Class.class)).
1988                     invokeExact(array, 0, "foo", Void.class);
1989             });
1990             checkWMTE(() -> { // array primitive class
1991                 String x = (String) hs.get(am, methodType(type, int.class, int.class, type, type)).
1992                     invokeExact(0, 0, "foo", "foo");
1993             });
1994             checkWMTE(() -> { // index reference class
1995                 String x = (String) hs.get(am, methodType(type, String[].class, Class.class, type, type)).
1996                     invokeExact(array, Void.class, "foo", "foo");
1997             });
1998             // Incorrect return type
1999             hs.checkWMTEOrCCE(() -> { // reference class
2000                 Void r = (Void) hs.get(am, methodType(Void.class, String[].class, int.class, type, type)).
2001                     invokeExact(array, 0, "foo", "foo");
2002             });
2003             checkWMTE(() -> { // primitive class
2004                 boolean x = (boolean) hs.get(am, methodType(boolean.class, String[].class, int.class, type, type)).
2005                     invokeExact(array, 0, "foo", "foo");
2006             });
2007             // Incorrect arity
2008             checkWMTE(() -> { // 0
2009                 String x = (String) hs.get(am, methodType(type)).
2010                     invokeExact();
2011             });
2012             checkWMTE(() -> { // >
2013                 String x = (String) hs.get(am, methodType(type, String[].class, int.class, type, type, Class.class)).
2014                     invokeExact(array, 0, "foo", "foo", Void.class);
2015             });
2016         }
2017 
2018         for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
2019             // Incorrect argument types
2020             checkNPE(() -> { // null array
2021                 String x = (String) hs.get(am, methodType(type, String[].class, int.class, type)).
2022                     invokeExact((String[]) null, 0, "foo");
2023             });
2024             hs.checkWMTEOrCCE(() -> { // array reference class
2025                 String x = (String) hs.get(am, methodType(type, Class.class, int.class, type)).
2026                     invokeExact(Void.class, 0, "foo");
2027             });
2028             hs.checkWMTEOrCCE(() -> { // value reference class
2029                 String x = (String) hs.get(am, methodType(type, String[].class, int.class, Class.class)).
2030                     invokeExact(array, 0, Void.class);
2031             });
2032             checkWMTE(() -> { // array primitive class
2033                 String x = (String) hs.get(am, methodType(type, int.class, int.class, type)).
2034                     invokeExact(0, 0, "foo");
2035             });
2036             checkWMTE(() -> { // index reference class
2037                 String x = (String) hs.get(am, methodType(type, String[].class, Class.class, type)).
2038                     invokeExact(array, Void.class, "foo");
2039             });
2040             // Incorrect return type
2041             hs.checkWMTEOrCCE(() -> { // reference class
2042                 Void r = (Void) hs.get(am, methodType(Void.class, String[].class, int.class, type)).
2043                     invokeExact(array, 0, "foo");
2044             });
2045             checkWMTE(() -> { // primitive class
2046                 boolean x = (boolean) hs.get(am, methodType(boolean.class, String[].class, int.class, type)).
2047                     invokeExact(array, 0, "foo");
2048             });
2049             // Incorrect arity
2050             checkWMTE(() -> { // 0
2051                 String x = (String) hs.get(am, methodType(type)).
2052                     invokeExact();
2053             });
2054             checkWMTE(() -> { // >
2055                 String x = (String) hs.get(am, methodType(type, String[].class, int.class, type, Class.class)).
2056                     invokeExact(array, 0, "foo", Void.class);
2057             });
2058         }
2059 
2060 
2061     }
2062 }