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