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