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