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