1 /*
   2  * Copyright (c) 2015, 2016 Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /*
  25  * @test
  26  * @run testng/othervm VarHandleTestMethodTypeShort
  27  * @run testng/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false VarHandleTestMethodTypeShort
  28  */
  29 
  30 import org.testng.annotations.BeforeClass;
  31 import org.testng.annotations.DataProvider;
  32 import org.testng.annotations.Test;
  33 
  34 import java.lang.invoke.MethodHandles;
  35 import java.lang.invoke.VarHandle;
  36 import java.util.ArrayList;
  37 import java.util.Arrays;
  38 import java.util.List;
  39 
  40 import static org.testng.Assert.*;
  41 
  42 import static java.lang.invoke.MethodType.*;
  43 
  44 public class VarHandleTestMethodTypeShort extends VarHandleBaseTest {
  45     static final short static_final_v = (short)1;
  46 
  47     static short static_v = (short)1;
  48 
  49     final short final_v = (short)1;
  50 
  51     short v = (short)1;
  52 
  53     VarHandle vhFinalField;
  54 
  55     VarHandle vhField;
  56 
  57     VarHandle vhStaticField;
  58 
  59     VarHandle vhStaticFinalField;
  60 
  61     VarHandle vhArray;
  62 
  63     @BeforeClass
  64     public void setup() throws Exception {
  65         vhFinalField = MethodHandles.lookup().findVarHandle(
  66                 VarHandleTestMethodTypeShort.class, "final_v", short.class);
  67 
  68         vhField = MethodHandles.lookup().findVarHandle(
  69                 VarHandleTestMethodTypeShort.class, "v", short.class);
  70 
  71         vhStaticFinalField = MethodHandles.lookup().findStaticVarHandle(
  72             VarHandleTestMethodTypeShort.class, "static_final_v", short.class);
  73 
  74         vhStaticField = MethodHandles.lookup().findStaticVarHandle(
  75             VarHandleTestMethodTypeShort.class, "static_v", short.class);
  76 
  77         vhArray = MethodHandles.arrayElementVarHandle(short[].class);
  78     }
  79 
  80     @DataProvider
  81     public Object[][] accessTestCaseProvider() throws Exception {
  82         List<AccessTestCase<?>> cases = new ArrayList<>();
  83 
  84         cases.add(new VarHandleAccessTestCase("Instance field wrong method type",
  85                                               vhField, vh -> testInstanceFieldWrongMethodType(this, vh),
  86                                               false));
  87 
  88         cases.add(new VarHandleAccessTestCase("Static field wrong method type",
  89                                               vhStaticField, VarHandleTestMethodTypeShort::testStaticFieldWrongMethodType,
  90                                               false));
  91 
  92         cases.add(new VarHandleAccessTestCase("Array wrong method type",
  93                                               vhArray, VarHandleTestMethodTypeShort::testArrayWrongMethodType,
  94                                               false));
  95         for (VarHandleToMethodHandle f : VarHandleToMethodHandle.values()) {
  96             cases.add(new MethodHandleAccessTestCase("Instance field wrong method type",
  97                                                      vhField, f, hs -> testInstanceFieldWrongMethodType(this, hs),
  98                                                      false));
  99 
 100             cases.add(new MethodHandleAccessTestCase("Static field wrong method type",
 101                                                      vhStaticField, f, VarHandleTestMethodTypeShort::testStaticFieldWrongMethodType,
 102                                                      false));
 103 
 104             cases.add(new MethodHandleAccessTestCase("Array wrong method type",
 105                                                      vhArray, f, VarHandleTestMethodTypeShort::testArrayWrongMethodType,
 106                                                      false));
 107         }
 108         // Work around issue with jtreg summary reporting which truncates
 109         // the String result of Object.toString to 30 characters, hence
 110         // the first dummy argument
 111         return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new);
 112     }
 113 
 114     @Test(dataProvider = "accessTestCaseProvider")
 115     public <T> void testAccess(String desc, AccessTestCase<T> atc) throws Throwable {
 116         T t = atc.get();
 117         int iters = atc.requiresLoop() ? ITERS : 1;
 118         for (int c = 0; c < iters; c++) {
 119             atc.testAccess(t);
 120         }
 121     }
 122 
 123 
 124     static void testInstanceFieldWrongMethodType(VarHandleTestMethodTypeShort recv, VarHandle vh) throws Throwable {
 125         // Get
 126         // Incorrect argument types
 127         checkNPE(() -> { // null receiver
 128             short x = (short) vh.get(null);
 129         });
 130         checkCCE(() -> { // receiver reference class
 131             short x = (short) vh.get(Void.class);
 132         });
 133         checkWMTE(() -> { // receiver primitive class
 134             short x = (short) vh.get(0);
 135         });
 136         // Incorrect return type
 137         checkWMTE(() -> { // reference class
 138             Void x = (Void) vh.get(recv);
 139         });
 140         checkWMTE(() -> { // primitive class
 141             boolean x = (boolean) vh.get(recv);
 142         });
 143         // Incorrect arity
 144         checkWMTE(() -> { // 0
 145             short x = (short) vh.get();
 146         });
 147         checkWMTE(() -> { // >
 148             short x = (short) vh.get(recv, Void.class);
 149         });
 150 
 151 
 152         // Set
 153         // Incorrect argument types
 154         checkNPE(() -> { // null receiver
 155             vh.set(null, (short)1);
 156         });
 157         checkCCE(() -> { // receiver reference class
 158             vh.set(Void.class, (short)1);
 159         });
 160         checkWMTE(() -> { // value reference class
 161             vh.set(recv, Void.class);
 162         });
 163         checkWMTE(() -> { // receiver primitive class
 164             vh.set(0, (short)1);
 165         });
 166         // Incorrect arity
 167         checkWMTE(() -> { // 0
 168             vh.set();
 169         });
 170         checkWMTE(() -> { // >
 171             vh.set(recv, (short)1, Void.class);
 172         });
 173 
 174 
 175         // GetVolatile
 176         // Incorrect argument types
 177         checkNPE(() -> { // null receiver
 178             short x = (short) vh.getVolatile(null);
 179         });
 180         checkCCE(() -> { // receiver reference class
 181             short x = (short) vh.getVolatile(Void.class);
 182         });
 183         checkWMTE(() -> { // receiver primitive class
 184             short x = (short) vh.getVolatile(0);
 185         });
 186         // Incorrect return type
 187         checkWMTE(() -> { // reference class
 188             Void x = (Void) vh.getVolatile(recv);
 189         });
 190         checkWMTE(() -> { // primitive class
 191             boolean x = (boolean) vh.getVolatile(recv);
 192         });
 193         // Incorrect arity
 194         checkWMTE(() -> { // 0
 195             short x = (short) vh.getVolatile();
 196         });
 197         checkWMTE(() -> { // >
 198             short x = (short) vh.getVolatile(recv, Void.class);
 199         });
 200 
 201 
 202         // SetVolatile
 203         // Incorrect argument types
 204         checkNPE(() -> { // null receiver
 205             vh.setVolatile(null, (short)1);
 206         });
 207         checkCCE(() -> { // receiver reference class
 208             vh.setVolatile(Void.class, (short)1);
 209         });
 210         checkWMTE(() -> { // value reference class
 211             vh.setVolatile(recv, Void.class);
 212         });
 213         checkWMTE(() -> { // receiver primitive class
 214             vh.setVolatile(0, (short)1);
 215         });
 216         // Incorrect arity
 217         checkWMTE(() -> { // 0
 218             vh.setVolatile();
 219         });
 220         checkWMTE(() -> { // >
 221             vh.setVolatile(recv, (short)1, Void.class);
 222         });
 223 
 224 
 225         // GetOpaque
 226         // Incorrect argument types
 227         checkNPE(() -> { // null receiver
 228             short x = (short) vh.getOpaque(null);
 229         });
 230         checkCCE(() -> { // receiver reference class
 231             short x = (short) vh.getOpaque(Void.class);
 232         });
 233         checkWMTE(() -> { // receiver primitive class
 234             short x = (short) vh.getOpaque(0);
 235         });
 236         // Incorrect return type
 237         checkWMTE(() -> { // reference class
 238             Void x = (Void) vh.getOpaque(recv);
 239         });
 240         checkWMTE(() -> { // primitive class
 241             boolean x = (boolean) vh.getOpaque(recv);
 242         });
 243         // Incorrect arity
 244         checkWMTE(() -> { // 0
 245             short x = (short) vh.getOpaque();
 246         });
 247         checkWMTE(() -> { // >
 248             short x = (short) vh.getOpaque(recv, Void.class);
 249         });
 250 
 251 
 252         // SetOpaque
 253         // Incorrect argument types
 254         checkNPE(() -> { // null receiver
 255             vh.setOpaque(null, (short)1);
 256         });
 257         checkCCE(() -> { // receiver reference class
 258             vh.setOpaque(Void.class, (short)1);
 259         });
 260         checkWMTE(() -> { // value reference class
 261             vh.setOpaque(recv, Void.class);
 262         });
 263         checkWMTE(() -> { // receiver primitive class
 264             vh.setOpaque(0, (short)1);
 265         });
 266         // Incorrect arity
 267         checkWMTE(() -> { // 0
 268             vh.setOpaque();
 269         });
 270         checkWMTE(() -> { // >
 271             vh.setOpaque(recv, (short)1, Void.class);
 272         });
 273 
 274 
 275         // GetAcquire
 276         // Incorrect argument types
 277         checkNPE(() -> { // null receiver
 278             short x = (short) vh.getAcquire(null);
 279         });
 280         checkCCE(() -> { // receiver reference class
 281             short x = (short) vh.getAcquire(Void.class);
 282         });
 283         checkWMTE(() -> { // receiver primitive class
 284             short x = (short) vh.getAcquire(0);
 285         });
 286         // Incorrect return type
 287         checkWMTE(() -> { // reference class
 288             Void x = (Void) vh.getAcquire(recv);
 289         });
 290         checkWMTE(() -> { // primitive class
 291             boolean x = (boolean) vh.getAcquire(recv);
 292         });
 293         // Incorrect arity
 294         checkWMTE(() -> { // 0
 295             short x = (short) vh.getAcquire();
 296         });
 297         checkWMTE(() -> { // >
 298             short x = (short) vh.getAcquire(recv, Void.class);
 299         });
 300 
 301 
 302         // SetRelease
 303         // Incorrect argument types
 304         checkNPE(() -> { // null receiver
 305             vh.setRelease(null, (short)1);
 306         });
 307         checkCCE(() -> { // receiver reference class
 308             vh.setRelease(Void.class, (short)1);
 309         });
 310         checkWMTE(() -> { // value reference class
 311             vh.setRelease(recv, Void.class);
 312         });
 313         checkWMTE(() -> { // receiver primitive class
 314             vh.setRelease(0, (short)1);
 315         });
 316         // Incorrect arity
 317         checkWMTE(() -> { // 0
 318             vh.setRelease();
 319         });
 320         checkWMTE(() -> { // >
 321             vh.setRelease(recv, (short)1, Void.class);
 322         });
 323 
 324 







































































































































































































































































































































































































































































































































































































































































































































































































































































 325 



















 326     }
 327 
 328     static void testInstanceFieldWrongMethodType(VarHandleTestMethodTypeShort recv, Handles hs) throws Throwable {


 329         for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET)) {
 330             // Incorrect argument types
 331             checkNPE(() -> { // null receiver
 332                 short x = (short) hs.get(am, methodType(short.class, Void.class)).
 333                     invoke(null);
 334             });
 335             checkCCE(() -> { // receiver reference class
 336                 short x = (short) hs.get(am, methodType(short.class, Class.class)).





 337                     invoke(Void.class);
 338             });
 339             checkWMTE(() -> { // receiver primitive class
 340                 short x = (short) hs.get(am, methodType(short.class, int.class)).
 341                     invoke(0);












































 342             });
 343             // Incorrect return type
 344             checkWMTE(() -> { // reference class
 345                 Void x = (Void) hs.get(am, methodType(short.class, VarHandleTestMethodTypeShort.class)).
 346                     invoke(recv);
 347             });
 348             checkWMTE(() -> { // primitive class
 349                 boolean x = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeShort.class)).
 350                     invoke(recv);
 351             });
 352             // Incorrect arity
 353             checkWMTE(() -> { // 0
 354                 short x = (short) hs.get(am, methodType(short.class)).
 355                     invoke();
 356             });
 357             checkWMTE(() -> { // >
 358                 short x = (short) hs.get(am, methodType(short.class, VarHandleTestMethodTypeShort.class, Class.class)).
 359                     invoke(recv, Void.class);
 360             });
 361         }
 362 
 363         for (TestAccessMode am : testAccessModesOfType(TestAccessType.SET)) {
 364             // Incorrect argument types
 365             checkNPE(() -> { // null receiver
 366                 hs.get(am, methodType(void.class, Void.class, short.class)).
 367                     invoke(null, (short)1);
 368             });
 369             checkCCE(() -> { // receiver reference class
 370                 hs.get(am, methodType(void.class, Class.class, short.class)).
 371                     invoke(Void.class, (short)1);










 372             });








 373             checkWMTE(() -> { // value reference class
 374                 hs.get(am, methodType(void.class, VarHandleTestMethodTypeShort.class, Class.class)).
 375                     invoke(recv, Void.class);
 376             });
 377             checkWMTE(() -> { // receiver primitive class
 378                 hs.get(am, methodType(void.class, int.class, short.class)).
 379                     invoke(0, (short)1);





 380             });
 381             // Incorrect arity
 382             checkWMTE(() -> { // 0
 383                 hs.get(am, methodType(void.class)).
 384                     invoke();
 385             });
 386             checkWMTE(() -> { // >
 387                 hs.get(am, methodType(void.class, VarHandleTestMethodTypeShort.class, short.class, Class.class)).
 388                     invoke(recv, (short)1, Void.class);
 389             });
 390         }
 391 
 392 
 393     }
 394 
 395 
 396     static void testStaticFieldWrongMethodType(VarHandle vh) throws Throwable {



 397         // Get













 398         // Incorrect return type
 399         checkWMTE(() -> { // reference class
 400             Void x = (Void) vh.get();
 401         });
 402         checkWMTE(() -> { // primitive class
 403             boolean x = (boolean) vh.get();
 404         });
 405         // Incorrect arity



 406         checkWMTE(() -> { // >
 407             short x = (short) vh.get(Void.class);
 408         });
 409 
 410 
 411         // Set
 412         // Incorrect argument types






 413         checkWMTE(() -> { // value reference class
 414             vh.set(Void.class);






 415         });
 416         // Incorrect arity
 417         checkWMTE(() -> { // 0
 418             vh.set();
 419         });
 420         checkWMTE(() -> { // >
 421             vh.set((short)1, Void.class);
 422         });
 423 
 424 
 425         // GetVolatile













 426         // Incorrect return type
 427         checkWMTE(() -> { // reference class
 428             Void x = (Void) vh.getVolatile();
 429         });
 430         checkWMTE(() -> { // primitive class
 431             boolean x = (boolean) vh.getVolatile();




 432         });
 433         checkWMTE(() -> { // >
 434             short x = (short) vh.getVolatile(Void.class);
 435         });
 436 
 437 
 438         // SetVolatile
 439         // Incorrect argument types






 440         checkWMTE(() -> { // value reference class
 441             vh.setVolatile(Void.class);






 442         });
 443         // Incorrect arity
 444         checkWMTE(() -> { // 0
 445             vh.setVolatile();
 446         });
 447         checkWMTE(() -> { // >
 448             vh.setVolatile((short)1, Void.class);
 449         });
 450 
 451 
 452         // GetOpaque













 453         // Incorrect return type
 454         checkWMTE(() -> { // reference class
 455             Void x = (Void) vh.getOpaque();
 456         });
 457         checkWMTE(() -> { // primitive class
 458             boolean x = (boolean) vh.getOpaque();




 459         });
 460         checkWMTE(() -> { // >
 461             short x = (short) vh.getOpaque(Void.class);
 462         });
 463 
 464 
 465         // SetOpaque
 466         // Incorrect argument types






 467         checkWMTE(() -> { // value reference class
 468             vh.setOpaque(Void.class);






 469         });
 470         // Incorrect arity
 471         checkWMTE(() -> { // 0
 472             vh.setOpaque();
 473         });
 474         checkWMTE(() -> { // >
 475             vh.setOpaque((short)1, Void.class);
 476         });
 477 
 478 
 479         // GetAcquire













 480         // Incorrect return type
 481         checkWMTE(() -> { // reference class
 482             Void x = (Void) vh.getAcquire();


























































 483         });
 484         checkWMTE(() -> { // primitive class
 485             boolean x = (boolean) vh.getAcquire();

 486         });
 487         checkWMTE(() -> { // >
 488             short x = (short) vh.getAcquire(Void.class);
 489         });
 490 
 491 
 492         // SetRelease
 493         // Incorrect argument types
 494         checkWMTE(() -> { // value reference class
 495             vh.setRelease(Void.class);















 496         });
 497         // Incorrect arity
 498         checkWMTE(() -> { // 0
 499             vh.setRelease();
 500         });
 501         checkWMTE(() -> { // >
 502             vh.setRelease((short)1, Void.class);
 503         });
 504 
 505 
 506 
 507     }
 508 
 509     static void testStaticFieldWrongMethodType(Handles hs) throws Throwable {
 510         int i = 0;
 511 
 512         for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET)) {
 513             // Incorrect return type
 514             checkWMTE(() -> { // reference class
 515                 Void x = (Void) hs.get(am, methodType(Void.class)).
 516                     invoke();
 517             });
 518             checkWMTE(() -> { // primitive class
 519                 boolean x = (boolean) hs.get(am, methodType(boolean.class)).
 520                     invoke();
 521             });
 522             // Incorrect arity
 523             checkWMTE(() -> { // >
 524                 short x = (short) hs.get(am, methodType(Class.class)).
 525                     invoke(Void.class);
 526             });
 527         }
 528 
 529         for (TestAccessMode am : testAccessModesOfType(TestAccessType.SET)) {
 530             checkWMTE(() -> { // value reference class
 531                 hs.get(am, methodType(void.class, Class.class)).
 532                     invoke(Void.class);


 533             });
 534             // Incorrect arity
 535             checkWMTE(() -> { // 0
 536                 hs.get(am, methodType(void.class)).
 537                     invoke();
 538             });
 539             checkWMTE(() -> { // >
 540                 hs.get(am, methodType(void.class, short.class, Class.class)).
 541                     invoke((short)1, Void.class);
 542             });
 543         }
 544 
 545     }
 546 
 547 
 548     static void testArrayWrongMethodType(VarHandle vh) throws Throwable {
 549         short[] array = new short[10];
 550         Arrays.fill(array, (short)1);
 551 
 552         // Get
 553         // Incorrect argument types
 554         checkNPE(() -> { // null array
 555             short x = (short) vh.get(null, 0);
 556         });
 557         checkCCE(() -> { // array reference class
 558             short x = (short) vh.get(Void.class, 0);
 559         });
 560         checkWMTE(() -> { // array primitive class
 561             short x = (short) vh.get(0, 0);
 562         });
 563         checkWMTE(() -> { // index reference class
 564             short x = (short) vh.get(array, Void.class);
 565         });
 566         // Incorrect return type
 567         checkWMTE(() -> { // reference class
 568             Void x = (Void) vh.get(array, 0);
 569         });
 570         checkWMTE(() -> { // primitive class
 571             boolean x = (boolean) vh.get(array, 0);
 572         });
 573         // Incorrect arity
 574         checkWMTE(() -> { // 0
 575             short x = (short) vh.get();
 576         });
 577         checkWMTE(() -> { // >
 578             short x = (short) vh.get(array, 0, Void.class);
 579         });
 580 
 581 
 582         // Set
 583         // Incorrect argument types
 584         checkNPE(() -> { // null array
 585             vh.set(null, 0, (short)1);
 586         });
 587         checkCCE(() -> { // array reference class
 588             vh.set(Void.class, 0, (short)1);
 589         });
 590         checkWMTE(() -> { // value reference class
 591             vh.set(array, 0, Void.class);



 592         });
 593         checkWMTE(() -> { // receiver primitive class
 594             vh.set(0, 0, (short)1);
 595         });
 596         checkWMTE(() -> { // index reference class
 597             vh.set(array, Void.class, (short)1);
 598         });
 599         // Incorrect arity
 600         checkWMTE(() -> { // 0
 601             vh.set();
 602         });
 603         checkWMTE(() -> { // >
 604             vh.set(array, 0, (short)1, Void.class);
 605         });
 606 
 607 
 608         // GetVolatile
 609         // Incorrect argument types
 610         checkNPE(() -> { // null array
 611             short x = (short) vh.getVolatile(null, 0);
 612         });
 613         checkCCE(() -> { // array reference class
 614             short x = (short) vh.getVolatile(Void.class, 0);






 615         });
 616         checkWMTE(() -> { // array primitive class
 617             short x = (short) vh.getVolatile(0, 0);
 618         });
 619         checkWMTE(() -> { // index reference class
 620             short x = (short) vh.getVolatile(array, Void.class);
 621         });
 622         // Incorrect return type
 623         checkWMTE(() -> { // reference class
 624             Void x = (Void) vh.getVolatile(array, 0);
 625         });
 626         checkWMTE(() -> { // primitive class
 627             boolean x = (boolean) vh.getVolatile(array, 0);
 628         });
 629         // Incorrect arity
 630         checkWMTE(() -> { // 0
 631             short x = (short) vh.getVolatile();
 632         });
 633         checkWMTE(() -> { // >
 634             short x = (short) vh.getVolatile(array, 0, Void.class);
 635         });
 636 
 637 
 638         // SetVolatile
 639         // Incorrect argument types
 640         checkNPE(() -> { // null array
 641             vh.setVolatile(null, 0, (short)1);
 642         });
 643         checkCCE(() -> { // array reference class
 644             vh.setVolatile(Void.class, 0, (short)1);
 645         });
 646         checkWMTE(() -> { // value reference class
 647             vh.setVolatile(array, 0, Void.class);
 648         });
 649         checkWMTE(() -> { // receiver primitive class
 650             vh.setVolatile(0, 0, (short)1);



 651         });
 652         checkWMTE(() -> { // index reference class
 653             vh.setVolatile(array, Void.class, (short)1);







 654         });
 655         // Incorrect arity
 656         checkWMTE(() -> { // 0
 657             vh.setVolatile();
 658         });
 659         checkWMTE(() -> { // >
 660             vh.setVolatile(array, 0, (short)1, Void.class);
 661         });
 662 
 663 
 664         // GetOpaque
 665         // Incorrect argument types
 666         checkNPE(() -> { // null array
 667             short x = (short) vh.getOpaque(null, 0);
 668         });
 669         checkCCE(() -> { // array reference class
 670             short x = (short) vh.getOpaque(Void.class, 0);






 671         });
 672         checkWMTE(() -> { // array primitive class
 673             short x = (short) vh.getOpaque(0, 0);
 674         });
 675         checkWMTE(() -> { // index reference class
 676             short x = (short) vh.getOpaque(array, Void.class);
 677         });
 678         // Incorrect return type
 679         checkWMTE(() -> { // reference class
 680             Void x = (Void) vh.getOpaque(array, 0);
 681         });
 682         checkWMTE(() -> { // primitive class
 683             boolean x = (boolean) vh.getOpaque(array, 0);
 684         });
 685         // Incorrect arity
 686         checkWMTE(() -> { // 0
 687             short x = (short) vh.getOpaque();
 688         });
 689         checkWMTE(() -> { // >
 690             short x = (short) vh.getOpaque(array, 0, Void.class);
 691         });
 692 
 693 
 694         // SetOpaque
 695         // Incorrect argument types
 696         checkNPE(() -> { // null array
 697             vh.setOpaque(null, 0, (short)1);
 698         });
 699         checkCCE(() -> { // array reference class
 700             vh.setOpaque(Void.class, 0, (short)1);
 701         });
 702         checkWMTE(() -> { // value reference class
 703             vh.setOpaque(array, 0, Void.class);
 704         });
 705         checkWMTE(() -> { // receiver primitive class
 706             vh.setOpaque(0, 0, (short)1);
 707         });
 708         checkWMTE(() -> { // index reference class
 709             vh.setOpaque(array, Void.class, (short)1);







 710         });
 711         // Incorrect arity
 712         checkWMTE(() -> { // 0
 713             vh.setOpaque();
 714         });
 715         checkWMTE(() -> { // >
 716             vh.setOpaque(array, 0, (short)1, Void.class);
 717         });
 718 
 719 
 720         // GetAcquire
 721         // Incorrect argument types
 722         checkNPE(() -> { // null array
 723             short x = (short) vh.getAcquire(null, 0);
 724         });
 725         checkCCE(() -> { // array reference class
 726             short x = (short) vh.getAcquire(Void.class, 0);



 727         });
 728         checkWMTE(() -> { // array primitive class
 729             short x = (short) vh.getAcquire(0, 0);
 730         });
 731         checkWMTE(() -> { // index reference class
 732             short x = (short) vh.getAcquire(array, Void.class);
 733         });
 734         // Incorrect return type
 735         checkWMTE(() -> { // reference class
 736             Void x = (Void) vh.getAcquire(array, 0);
 737         });
 738         checkWMTE(() -> { // primitive class
 739             boolean x = (boolean) vh.getAcquire(array, 0);
 740         });
 741         // Incorrect arity
 742         checkWMTE(() -> { // 0
 743             short x = (short) vh.getAcquire();
 744         });
 745         checkWMTE(() -> { // >
 746             short x = (short) vh.getAcquire(array, 0, Void.class);
 747         });
 748 
 749 
 750         // SetRelease
 751         // Incorrect argument types
 752         checkNPE(() -> { // null array
 753             vh.setRelease(null, 0, (short)1);
 754         });
 755         checkCCE(() -> { // array reference class
 756             vh.setRelease(Void.class, 0, (short)1);
 757         });
 758         checkWMTE(() -> { // value reference class
 759             vh.setRelease(array, 0, Void.class);
 760         });
 761         checkWMTE(() -> { // receiver primitive class
 762             vh.setRelease(0, 0, (short)1);
 763         });
 764         checkWMTE(() -> { // index reference class
 765             vh.setRelease(array, Void.class, (short)1);







 766         });
 767         // Incorrect arity
 768         checkWMTE(() -> { // 0
 769             vh.setRelease();
 770         });
 771         checkWMTE(() -> { // >
 772             vh.setRelease(array, 0, (short)1, Void.class);
 773         });
 774 
 775 
 776 
 777     }
 778 
 779     static void testArrayWrongMethodType(Handles hs) throws Throwable {
 780         short[] array = new short[10];
 781         Arrays.fill(array, (short)1);
 782 
 783         for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET)) {
 784             // Incorrect argument types
 785             checkNPE(() -> { // null array
 786                 short x = (short) hs.get(am, methodType(short.class, Void.class, int.class)).
 787                     invoke(null, 0);
 788             });
 789             checkCCE(() -> { // array reference class
 790                 short x = (short) hs.get(am, methodType(short.class, Class.class, int.class)).
 791                     invoke(Void.class, 0);
 792             });
 793             checkWMTE(() -> { // array primitive class
 794                 short x = (short) hs.get(am, methodType(short.class, int.class, int.class)).
 795                     invoke(0, 0);
 796             });
 797             checkWMTE(() -> { // index reference class
 798                 short x = (short) hs.get(am, methodType(short.class, short[].class, Class.class)).
 799                     invoke(array, Void.class);
 800             });
 801             // Incorrect return type
 802             checkWMTE(() -> { // reference class
 803                 Void x = (Void) hs.get(am, methodType(Void.class, short[].class, int.class)).
 804                     invoke(array, 0);
 805             });
 806             checkWMTE(() -> { // primitive class
 807                 boolean x = (boolean) hs.get(am, methodType(boolean.class, short[].class, int.class)).
 808                     invoke(array, 0);
 809             });
 810             // Incorrect arity
 811             checkWMTE(() -> { // 0
 812                 short x = (short) hs.get(am, methodType(short.class)).
 813                     invoke();
 814             });
 815             checkWMTE(() -> { // >
 816                 short x = (short) hs.get(am, methodType(short.class, short[].class, int.class, Class.class)).
 817                     invoke(array, 0, Void.class);
 818             });
 819         }
 820 
 821         for (TestAccessMode am : testAccessModesOfType(TestAccessType.SET)) {
 822             // Incorrect argument types
 823             checkNPE(() -> { // null array
 824                 hs.get(am, methodType(void.class, Void.class, int.class, short.class)).
 825                     invoke(null, 0, (short)1);
 826             });
 827             checkCCE(() -> { // array reference class
 828                 hs.get(am, methodType(void.class, Class.class, int.class, short.class)).
 829                     invoke(Void.class, 0, (short)1);
 830             });
 831             checkWMTE(() -> { // value reference class
 832                 hs.get(am, methodType(void.class, short[].class, int.class, Class.class)).
 833                     invoke(array, 0, Void.class);
 834             });
 835             checkWMTE(() -> { // receiver primitive class
 836                 hs.get(am, methodType(void.class, int.class, int.class, short.class)).
 837                     invoke(0, 0, (short)1);
 838             });
 839             checkWMTE(() -> { // index reference class
 840                 hs.get(am, methodType(void.class, short[].class, Class.class, short.class)).
 841                     invoke(array, Void.class, (short)1);
 842             });
 843             // Incorrect arity
 844             checkWMTE(() -> { // 0
 845                 hs.get(am, methodType(void.class)).
 846                     invoke();
 847             });
 848             checkWMTE(() -> { // >
 849                 hs.get(am, methodType(void.class, short[].class, int.class, Class.class)).
 850                     invoke(array, 0, (short)1, Void.class);




























































































































 851             });
 852         }
 853 









































 854     }
 855 }
 856 
--- EOF ---