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