< prev index next >

test/jdk/java/lang/invoke/VarHandles/VarHandleTestMethodTypeDouble.java

Print this page

   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 VarHandleTestMethodTypeDouble
  28  * @run testng/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=true -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true VarHandleTestMethodTypeDouble
  29  * @run testng/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=false VarHandleTestMethodTypeDouble
  30  * @run testng/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true VarHandleTestMethodTypeDouble
  31  */
  32 
  33 import org.testng.annotations.BeforeClass;
  34 import org.testng.annotations.DataProvider;
  35 import org.testng.annotations.Test;
  36 
  37 import java.lang.invoke.MethodHandles;
  38 import java.lang.invoke.VarHandle;
  39 import java.util.ArrayList;
  40 import java.util.Arrays;
  41 import java.util.List;
  42 
  43 import static org.testng.Assert.*;
  44 
  45 import static java.lang.invoke.MethodType.*;
  46 
  47 public class VarHandleTestMethodTypeDouble extends VarHandleBaseTest {


  48     static final double static_final_v = 1.0d;
  49 
  50     static double static_v = 1.0d;
  51 
  52     final double final_v = 1.0d;
  53 
  54     double v = 1.0d;
  55 
  56     VarHandle vhFinalField;
  57 
  58     VarHandle vhField;
  59 
  60     VarHandle vhStaticField;
  61 
  62     VarHandle vhStaticFinalField;
  63 
  64     VarHandle vhArray;
  65 
  66     @BeforeClass
  67     public void setup() throws Exception {
  68         vhFinalField = MethodHandles.lookup().findVarHandle(
  69                 VarHandleTestMethodTypeDouble.class, "final_v", double.class);
  70 
  71         vhField = MethodHandles.lookup().findVarHandle(
  72                 VarHandleTestMethodTypeDouble.class, "v", double.class);
  73 
  74         vhStaticFinalField = MethodHandles.lookup().findStaticVarHandle(
  75             VarHandleTestMethodTypeDouble.class, "static_final_v", double.class);
  76 
  77         vhStaticField = MethodHandles.lookup().findStaticVarHandle(
  78             VarHandleTestMethodTypeDouble.class, "static_v", double.class);
  79 
  80         vhArray = MethodHandles.arrayElementVarHandle(double[].class);
  81     }
  82 
  83     @DataProvider
  84     public Object[][] accessTestCaseProvider() throws Exception {
  85         List<AccessTestCase<?>> cases = new ArrayList<>();
  86 
  87         cases.add(new VarHandleAccessTestCase("Instance field",
  88                                               vhField, vh -> testInstanceFieldWrongMethodType(this, vh),
  89                                               false));
  90 
  91         cases.add(new VarHandleAccessTestCase("Static field",
  92                                               vhStaticField, VarHandleTestMethodTypeDouble::testStaticFieldWrongMethodType,
  93                                               false));
  94 
  95         cases.add(new VarHandleAccessTestCase("Array",
  96                                               vhArray, VarHandleTestMethodTypeDouble::testArrayWrongMethodType,
  97                                               false));
  98 

 718         checkWMTE(() -> { // reference class
 719             Void r = (Void) vh.getAndAddRelease(recv, 1.0d);
 720         });
 721         checkWMTE(() -> { // primitive class
 722             boolean x = (boolean) vh.getAndAddRelease(recv, 1.0d);
 723         });
 724         // Incorrect arity
 725         checkWMTE(() -> { // 0
 726             double x = (double) vh.getAndAddRelease();
 727         });
 728         checkWMTE(() -> { // >
 729             double x = (double) vh.getAndAddRelease(recv, 1.0d, Void.class);
 730         });
 731 
 732     }
 733 
 734     static void testInstanceFieldWrongMethodType(VarHandleTestMethodTypeDouble recv, Handles hs) throws Throwable {
 735         for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET)) {
 736             // Incorrect argument types
 737             checkNPE(() -> { // null receiver
 738                 double x = (double) hs.get(am, methodType(double.class, VarHandleTestMethodTypeDouble.class)).
 739                     invokeExact((VarHandleTestMethodTypeDouble) null);
 740             });
 741             hs.checkWMTEOrCCE(() -> { // receiver reference class
 742                 double x = (double) hs.get(am, methodType(double.class, Class.class)).
 743                     invokeExact(Void.class);
 744             });
 745             checkWMTE(() -> { // receiver primitive class
 746                 double x = (double) hs.get(am, methodType(double.class, int.class)).
 747                     invokeExact(0);
 748             });
 749             // Incorrect return type
 750             checkWMTE(() -> { // reference class
 751                 Void x = (Void) hs.get(am, methodType(Void.class, VarHandleTestMethodTypeDouble.class)).
 752                     invokeExact(recv);
 753             });
 754             checkWMTE(() -> { // primitive class
 755                 boolean x = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeDouble.class)).
 756                     invokeExact(recv);
 757             });
 758             // Incorrect arity
 759             checkWMTE(() -> { // 0
 760                 double x = (double) hs.get(am, methodType(double.class)).
 761                     invokeExact();
 762             });
 763             checkWMTE(() -> { // >
 764                 double x = (double) hs.get(am, methodType(double.class, VarHandleTestMethodTypeDouble.class, Class.class)).
 765                     invokeExact(recv, Void.class);
 766             });
 767         }
 768 
 769         for (TestAccessMode am : testAccessModesOfType(TestAccessType.SET)) {
 770             // Incorrect argument types
 771             checkNPE(() -> { // null receiver
 772                 hs.get(am, methodType(void.class, VarHandleTestMethodTypeDouble.class, double.class)).
 773                     invokeExact((VarHandleTestMethodTypeDouble) null, 1.0d);
 774             });
 775             hs.checkWMTEOrCCE(() -> { // receiver reference class
 776                 hs.get(am, methodType(void.class, Class.class, double.class)).
 777                     invokeExact(Void.class, 1.0d);
 778             });
 779             checkWMTE(() -> { // value reference class
 780                 hs.get(am, methodType(void.class, VarHandleTestMethodTypeDouble.class, Class.class)).
 781                     invokeExact(recv, Void.class);
 782             });
 783             checkWMTE(() -> { // receiver primitive class
 784                 hs.get(am, methodType(void.class, int.class, double.class)).
 785                     invokeExact(0, 1.0d);
 786             });
 787             // Incorrect arity
 788             checkWMTE(() -> { // 0
 789                 hs.get(am, methodType(void.class)).
 790                     invokeExact();
 791             });
 792             checkWMTE(() -> { // >
 793                 hs.get(am, methodType(void.class, VarHandleTestMethodTypeDouble.class, double.class, Class.class)).
 794                     invokeExact(recv, 1.0d, Void.class);
 795             });
 796         }
 797 
 798         for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
 799             // Incorrect argument types
 800             checkNPE(() -> { // null receiver
 801                 boolean r = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeDouble.class, double.class, double.class)).
 802                     invokeExact((VarHandleTestMethodTypeDouble) null, 1.0d, 1.0d);
 803             });
 804             hs.checkWMTEOrCCE(() -> { // receiver reference class
 805                 boolean r = (boolean) hs.get(am, methodType(boolean.class, Class.class, double.class, double.class)).
 806                     invokeExact(Void.class, 1.0d, 1.0d);
 807             });
 808             checkWMTE(() -> { // expected reference class
 809                 boolean r = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeDouble.class, Class.class, double.class)).
 810                     invokeExact(recv, Void.class, 1.0d);
 811             });
 812             checkWMTE(() -> { // actual reference class
 813                 boolean r = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeDouble.class, double.class, Class.class)).
 814                     invokeExact(recv, 1.0d, Void.class);
 815             });
 816             checkWMTE(() -> { // receiver primitive class
 817                 boolean r = (boolean) hs.get(am, methodType(boolean.class, int.class , double.class, double.class)).
 818                     invokeExact(0, 1.0d, 1.0d);
 819             });
 820             // Incorrect arity
 821             checkWMTE(() -> { // 0
 822                 boolean r = (boolean) hs.get(am, methodType(boolean.class)).
 823                     invokeExact();
 824             });
 825             checkWMTE(() -> { // >
 826                 boolean r = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeDouble.class, double.class, double.class, Class.class)).
 827                     invokeExact(recv, 1.0d, 1.0d, Void.class);
 828             });
 829         }
 830 
 831         for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
 832             checkNPE(() -> { // null receiver
 833                 double x = (double) hs.get(am, methodType(double.class, VarHandleTestMethodTypeDouble.class, double.class, double.class)).
 834                     invokeExact((VarHandleTestMethodTypeDouble) null, 1.0d, 1.0d);
 835             });
 836             hs.checkWMTEOrCCE(() -> { // receiver reference class
 837                 double x = (double) hs.get(am, methodType(double.class, Class.class, double.class, double.class)).
 838                     invokeExact(Void.class, 1.0d, 1.0d);
 839             });
 840             checkWMTE(() -> { // expected reference class
 841                 double x = (double) hs.get(am, methodType(double.class, VarHandleTestMethodTypeDouble.class, Class.class, double.class)).
 842                     invokeExact(recv, Void.class, 1.0d);
 843             });
 844             checkWMTE(() -> { // actual reference class
 845                 double x = (double) hs.get(am, methodType(double.class, VarHandleTestMethodTypeDouble.class, double.class, Class.class)).
 846                     invokeExact(recv, 1.0d, Void.class);
 847             });
 848             checkWMTE(() -> { // reciever primitive class
 849                 double x = (double) hs.get(am, methodType(double.class, int.class , double.class, double.class)).
 850                     invokeExact(0, 1.0d, 1.0d);
 851             });
 852             // Incorrect return type
 853             checkWMTE(() -> { // reference class
 854                 Void r = (Void) hs.get(am, methodType(Void.class, VarHandleTestMethodTypeDouble.class , double.class, double.class)).
 855                     invokeExact(recv, 1.0d, 1.0d);
 856             });
 857             checkWMTE(() -> { // primitive class
 858                 boolean x = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeDouble.class , double.class, double.class)).
 859                     invokeExact(recv, 1.0d, 1.0d);
 860             });
 861             // Incorrect arity
 862             checkWMTE(() -> { // 0
 863                 double x = (double) hs.get(am, methodType(double.class)).
 864                     invokeExact();
 865             });
 866             checkWMTE(() -> { // >
 867                 double x = (double) hs.get(am, methodType(double.class, VarHandleTestMethodTypeDouble.class, double.class, double.class, Class.class)).
 868                     invokeExact(recv, 1.0d, 1.0d, Void.class);
 869             });
 870         }
 871 
 872         for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
 873             checkNPE(() -> { // null receiver
 874                 double x = (double) hs.get(am, methodType(double.class, VarHandleTestMethodTypeDouble.class, double.class)).
 875                     invokeExact((VarHandleTestMethodTypeDouble) null, 1.0d);
 876             });
 877             hs.checkWMTEOrCCE(() -> { // receiver reference class
 878                 double x = (double) hs.get(am, methodType(double.class, Class.class, double.class)).
 879                     invokeExact(Void.class, 1.0d);
 880             });
 881             checkWMTE(() -> { // value reference class
 882                 double x = (double) hs.get(am, methodType(double.class, VarHandleTestMethodTypeDouble.class, Class.class)).
 883                     invokeExact(recv, Void.class);
 884             });
 885             checkWMTE(() -> { // reciever primitive class
 886                 double x = (double) hs.get(am, methodType(double.class, int.class, double.class)).
 887                     invokeExact(0, 1.0d);
 888             });
 889             // Incorrect return type
 890             checkWMTE(() -> { // reference class
 891                 Void r = (Void) hs.get(am, methodType(Void.class, VarHandleTestMethodTypeDouble.class, double.class)).
 892                     invokeExact(recv, 1.0d);
 893             });
 894             checkWMTE(() -> { // primitive class
 895                 boolean x = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeDouble.class, double.class)).
 896                     invokeExact(recv, 1.0d);
 897             });
 898             // Incorrect arity
 899             checkWMTE(() -> { // 0
 900                 double x = (double) hs.get(am, methodType(double.class)).
 901                     invokeExact();
 902             });
 903             checkWMTE(() -> { // >
 904                 double x = (double) hs.get(am, methodType(double.class, VarHandleTestMethodTypeDouble.class, double.class)).
 905                     invokeExact(recv, 1.0d, Void.class);
 906             });
 907         }
 908 
 909         for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) {
 910             checkNPE(() -> { // null receiver
 911                 double x = (double) hs.get(am, methodType(double.class, VarHandleTestMethodTypeDouble.class, double.class)).
 912                     invokeExact((VarHandleTestMethodTypeDouble) null, 1.0d);
 913             });
 914             hs.checkWMTEOrCCE(() -> { // receiver reference class
 915                 double x = (double) hs.get(am, methodType(double.class, Class.class, double.class)).
 916                     invokeExact(Void.class, 1.0d);
 917             });
 918             checkWMTE(() -> { // value reference class
 919                 double x = (double) hs.get(am, methodType(double.class, VarHandleTestMethodTypeDouble.class, Class.class)).
 920                     invokeExact(recv, Void.class);
 921             });
 922             checkWMTE(() -> { // reciever primitive class
 923                 double x = (double) hs.get(am, methodType(double.class, int.class, double.class)).
 924                     invokeExact(0, 1.0d);
 925             });
 926             // Incorrect return type
 927             checkWMTE(() -> { // reference class
 928                 Void r = (Void) hs.get(am, methodType(Void.class, VarHandleTestMethodTypeDouble.class, double.class)).
 929                     invokeExact(recv, 1.0d);
 930             });
 931             checkWMTE(() -> { // primitive class
 932                 boolean x = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeDouble.class, double.class)).
 933                     invokeExact(recv, 1.0d);
 934             });
 935             // Incorrect arity
 936             checkWMTE(() -> { // 0
 937                 double x = (double) hs.get(am, methodType(double.class)).
 938                     invokeExact();
 939             });
 940             checkWMTE(() -> { // >
 941                 double x = (double) hs.get(am, methodType(double.class, VarHandleTestMethodTypeDouble.class, double.class)).
 942                     invokeExact(recv, 1.0d, Void.class);
 943             });
 944         }
 945 
 946     }
 947 
 948 
 949     static void testStaticFieldWrongMethodType(VarHandle vh) throws Throwable {
 950         // Get
 951         // Incorrect return type
 952         checkWMTE(() -> { // reference class
 953             Void x = (Void) vh.get();
 954         });
 955         checkWMTE(() -> { // primitive class
 956             boolean x = (boolean) vh.get();
 957         });
 958         // Incorrect arity
 959         checkWMTE(() -> { // >
 960             double x = (double) vh.get(Void.class);
 961         });

1353                     invokeExact();
1354             });
1355             // Incorrect arity
1356             checkWMTE(() -> { // >
1357                 double x = (double) hs.get(am, methodType(Class.class)).
1358                     invokeExact(Void.class);
1359             });
1360         }
1361 
1362         for (TestAccessMode am : testAccessModesOfType(TestAccessType.SET)) {
1363             checkWMTE(() -> { // value reference class
1364                 hs.get(am, methodType(void.class, Class.class)).
1365                     invokeExact(Void.class);
1366             });
1367             // Incorrect arity
1368             checkWMTE(() -> { // 0
1369                 hs.get(am, methodType(void.class)).
1370                     invokeExact();
1371             });
1372             checkWMTE(() -> { // >
1373                 hs.get(am, methodType(void.class, double.class, Class.class)).
1374                     invokeExact(1.0d, Void.class);
1375             });
1376         }
1377         for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
1378             // Incorrect argument types
1379             checkWMTE(() -> { // expected reference class
1380                 boolean r = (boolean) hs.get(am, methodType(boolean.class, Class.class, double.class)).
1381                     invokeExact(Void.class, 1.0d);
1382             });
1383             checkWMTE(() -> { // actual reference class
1384                 boolean r = (boolean) hs.get(am, methodType(boolean.class, double.class, Class.class)).
1385                     invokeExact(1.0d, Void.class);
1386             });
1387             // Incorrect arity
1388             checkWMTE(() -> { // 0
1389                 boolean r = (boolean) hs.get(am, methodType(boolean.class)).
1390                     invokeExact();
1391             });
1392             checkWMTE(() -> { // >
1393                 boolean r = (boolean) hs.get(am, methodType(boolean.class, double.class, double.class, Class.class)).
1394                     invokeExact(1.0d, 1.0d, Void.class);
1395             });
1396         }
1397 
1398         for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
1399             // Incorrect argument types
1400             checkWMTE(() -> { // expected reference class
1401                 double x = (double) hs.get(am, methodType(double.class, Class.class, double.class)).
1402                     invokeExact(Void.class, 1.0d);
1403             });
1404             checkWMTE(() -> { // actual reference class
1405                 double x = (double) hs.get(am, methodType(double.class, double.class, Class.class)).
1406                     invokeExact(1.0d, Void.class);
1407             });
1408             // Incorrect return type
1409             checkWMTE(() -> { // reference class
1410                 Void r = (Void) hs.get(am, methodType(Void.class, double.class, double.class)).
1411                     invokeExact(1.0d, 1.0d);
1412             });
1413             checkWMTE(() -> { // primitive class
1414                 boolean x = (boolean) hs.get(am, methodType(boolean.class, double.class, double.class)).
1415                     invokeExact(1.0d, 1.0d);
1416             });
1417             // Incorrect arity
1418             checkWMTE(() -> { // 0
1419                 double x = (double) hs.get(am, methodType(double.class)).
1420                     invokeExact();
1421             });
1422             checkWMTE(() -> { // >
1423                 double x = (double) hs.get(am, methodType(double.class, double.class, double.class, Class.class)).
1424                     invokeExact(1.0d, 1.0d, Void.class);
1425             });
1426         }
1427 
1428         for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
1429             // Incorrect argument types
1430             checkWMTE(() -> { // value reference class
1431                 double x = (double) hs.get(am, methodType(double.class, Class.class)).
1432                     invokeExact(Void.class);
1433             });
1434             // Incorrect return type
1435             checkWMTE(() -> { // reference class
1436                 Void r = (Void) hs.get(am, methodType(Void.class, double.class)).
1437                     invokeExact(1.0d);
1438             });
1439             checkWMTE(() -> { // primitive class
1440                 boolean x = (boolean) hs.get(am, methodType(boolean.class, double.class)).
1441                     invokeExact(1.0d);
1442             });
1443             // Incorrect arity
1444             checkWMTE(() -> { // 0
1445                 double x = (double) hs.get(am, methodType(double.class)).
1446                     invokeExact();
1447             });
1448             checkWMTE(() -> { // >
1449                 double x = (double) hs.get(am, methodType(double.class, double.class, Class.class)).
1450                     invokeExact(1.0d, Void.class);
1451             });
1452         }
1453 
1454         for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) {
1455             // Incorrect argument types
1456             checkWMTE(() -> { // value reference class
1457                 double x = (double) hs.get(am, methodType(double.class, Class.class)).
1458                     invokeExact(Void.class);
1459             });
1460             // Incorrect return type
1461             checkWMTE(() -> { // reference class
1462                 Void r = (Void) hs.get(am, methodType(Void.class, double.class)).
1463                     invokeExact(1.0d);
1464             });
1465             checkWMTE(() -> { // primitive class
1466                 boolean x = (boolean) hs.get(am, methodType(boolean.class, double.class)).
1467                     invokeExact(1.0d);
1468             });
1469             // Incorrect arity
1470             checkWMTE(() -> { // 0
1471                 double x = (double) hs.get(am, methodType(double.class)).
1472                     invokeExact();
1473             });
1474             checkWMTE(() -> { // >
1475                 double x = (double) hs.get(am, methodType(double.class, double.class, Class.class)).
1476                     invokeExact(1.0d, Void.class);
1477             });
1478         }
1479 
1480     }
1481 
1482 
1483     static void testArrayWrongMethodType(VarHandle vh) throws Throwable {
1484         double[] array = new double[10];
1485         Arrays.fill(array, 1.0d);
1486 
1487         // Get
1488         // Incorrect argument types
1489         checkNPE(() -> { // null array
1490             double x = (double) vh.get(null, 0);
1491         });
1492         checkCCE(() -> { // array reference class
1493             double x = (double) vh.get(Void.class, 0);
1494         });
1495         checkWMTE(() -> { // array primitive class

2149         checkWMTE(() -> { // primitive class
2150             boolean x = (boolean) vh.getAndAddRelease(array, 0, 1.0d);
2151         });
2152         // Incorrect arity
2153         checkWMTE(() -> { // 0
2154             double x = (double) vh.getAndAddRelease();
2155         });
2156         checkWMTE(() -> { // >
2157             double x = (double) vh.getAndAddRelease(array, 0, 1.0d, Void.class);
2158         });
2159 
2160     }
2161 
2162     static void testArrayWrongMethodType(Handles hs) throws Throwable {
2163         double[] array = new double[10];
2164         Arrays.fill(array, 1.0d);
2165 
2166         for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET)) {
2167             // Incorrect argument types
2168             checkNPE(() -> { // null array
2169                 double x = (double) hs.get(am, methodType(double.class, double[].class, int.class)).
2170                     invokeExact((double[]) null, 0);
2171             });
2172             hs.checkWMTEOrCCE(() -> { // array reference class
2173                 double x = (double) hs.get(am, methodType(double.class, Class.class, int.class)).
2174                     invokeExact(Void.class, 0);
2175             });
2176             checkWMTE(() -> { // array primitive class
2177                 double x = (double) hs.get(am, methodType(double.class, int.class, int.class)).
2178                     invokeExact(0, 0);
2179             });
2180             checkWMTE(() -> { // index reference class
2181                 double x = (double) hs.get(am, methodType(double.class, double[].class, Class.class)).
2182                     invokeExact(array, Void.class);
2183             });
2184             // Incorrect return type
2185             checkWMTE(() -> { // reference class
2186                 Void x = (Void) hs.get(am, methodType(Void.class, double[].class, int.class)).
2187                     invokeExact(array, 0);
2188             });
2189             checkWMTE(() -> { // primitive class
2190                 boolean x = (boolean) hs.get(am, methodType(boolean.class, double[].class, int.class)).
2191                     invokeExact(array, 0);
2192             });
2193             // Incorrect arity
2194             checkWMTE(() -> { // 0
2195                 double x = (double) hs.get(am, methodType(double.class)).
2196                     invokeExact();
2197             });
2198             checkWMTE(() -> { // >
2199                 double x = (double) hs.get(am, methodType(double.class, double[].class, int.class, Class.class)).
2200                     invokeExact(array, 0, Void.class);
2201             });
2202         }
2203 
2204         for (TestAccessMode am : testAccessModesOfType(TestAccessType.SET)) {
2205             // Incorrect argument types
2206             checkNPE(() -> { // null array
2207                 hs.get(am, methodType(void.class, double[].class, int.class, double.class)).
2208                     invokeExact((double[]) null, 0, 1.0d);
2209             });
2210             hs.checkWMTEOrCCE(() -> { // array reference class
2211                 hs.get(am, methodType(void.class, Class.class, int.class, double.class)).
2212                     invokeExact(Void.class, 0, 1.0d);
2213             });
2214             checkWMTE(() -> { // value reference class
2215                 hs.get(am, methodType(void.class, double[].class, int.class, Class.class)).
2216                     invokeExact(array, 0, Void.class);
2217             });
2218             checkWMTE(() -> { // receiver primitive class
2219                 hs.get(am, methodType(void.class, int.class, int.class, double.class)).
2220                     invokeExact(0, 0, 1.0d);
2221             });
2222             checkWMTE(() -> { // index reference class
2223                 hs.get(am, methodType(void.class, double[].class, Class.class, double.class)).
2224                     invokeExact(array, Void.class, 1.0d);
2225             });
2226             // Incorrect arity
2227             checkWMTE(() -> { // 0
2228                 hs.get(am, methodType(void.class)).
2229                     invokeExact();
2230             });
2231             checkWMTE(() -> { // >
2232                 hs.get(am, methodType(void.class, double[].class, int.class, Class.class)).
2233                     invokeExact(array, 0, 1.0d, Void.class);
2234             });
2235         }
2236         for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
2237             // Incorrect argument types
2238             checkNPE(() -> { // null receiver
2239                 boolean r = (boolean) hs.get(am, methodType(boolean.class, double[].class, int.class, double.class, double.class)).
2240                     invokeExact((double[]) null, 0, 1.0d, 1.0d);
2241             });
2242             hs.checkWMTEOrCCE(() -> { // receiver reference class
2243                 boolean r = (boolean) hs.get(am, methodType(boolean.class, Class.class, int.class, double.class, double.class)).
2244                     invokeExact(Void.class, 0, 1.0d, 1.0d);
2245             });
2246             checkWMTE(() -> { // expected reference class
2247                 boolean r = (boolean) hs.get(am, methodType(boolean.class, double[].class, int.class, Class.class, double.class)).
2248                     invokeExact(array, 0, Void.class, 1.0d);
2249             });
2250             checkWMTE(() -> { // actual reference class
2251                 boolean r = (boolean) hs.get(am, methodType(boolean.class, double[].class, int.class, double.class, Class.class)).
2252                     invokeExact(array, 0, 1.0d, Void.class);
2253             });
2254             checkWMTE(() -> { // receiver primitive class
2255                 boolean r = (boolean) hs.get(am, methodType(boolean.class, int.class, int.class, double.class, double.class)).
2256                     invokeExact(0, 0, 1.0d, 1.0d);
2257             });
2258             checkWMTE(() -> { // index reference class
2259                 boolean r = (boolean) hs.get(am, methodType(boolean.class, double[].class, Class.class, double.class, double.class)).
2260                     invokeExact(array, Void.class, 1.0d, 1.0d);
2261             });
2262             // Incorrect arity
2263             checkWMTE(() -> { // 0
2264                 boolean r = (boolean) hs.get(am, methodType(boolean.class)).
2265                     invokeExact();
2266             });
2267             checkWMTE(() -> { // >
2268                 boolean r = (boolean) hs.get(am, methodType(boolean.class, double[].class, int.class, double.class, double.class, Class.class)).
2269                     invokeExact(array, 0, 1.0d, 1.0d, Void.class);
2270             });
2271         }
2272 
2273         for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
2274             // Incorrect argument types
2275             checkNPE(() -> { // null receiver
2276                 double x = (double) hs.get(am, methodType(double.class, double[].class, int.class, double.class, double.class)).
2277                     invokeExact((double[]) null, 0, 1.0d, 1.0d);
2278             });
2279             hs.checkWMTEOrCCE(() -> { // array reference class
2280                 double x = (double) hs.get(am, methodType(double.class, Class.class, int.class, double.class, double.class)).
2281                     invokeExact(Void.class, 0, 1.0d, 1.0d);
2282             });
2283             checkWMTE(() -> { // expected reference class
2284                 double x = (double) hs.get(am, methodType(double.class, double[].class, int.class, Class.class, double.class)).
2285                     invokeExact(array, 0, Void.class, 1.0d);
2286             });
2287             checkWMTE(() -> { // actual reference class
2288                 double x = (double) hs.get(am, methodType(double.class, double[].class, int.class, double.class, Class.class)).
2289                     invokeExact(array, 0, 1.0d, Void.class);
2290             });
2291             checkWMTE(() -> { // array primitive class
2292                 double x = (double) hs.get(am, methodType(double.class, int.class, int.class, double.class, double.class)).
2293                     invokeExact(0, 0, 1.0d, 1.0d);
2294             });
2295             checkWMTE(() -> { // index reference class
2296                 double x = (double) hs.get(am, methodType(double.class, double[].class, Class.class, double.class, double.class)).
2297                     invokeExact(array, Void.class, 1.0d, 1.0d);
2298             });
2299             // Incorrect return type
2300             checkWMTE(() -> { // reference class
2301                 Void r = (Void) hs.get(am, methodType(Void.class, double[].class, int.class, double.class, double.class)).
2302                     invokeExact(array, 0, 1.0d, 1.0d);
2303             });
2304             checkWMTE(() -> { // primitive class
2305                 boolean x = (boolean) hs.get(am, methodType(boolean.class, double[].class, int.class, double.class, double.class)).
2306                     invokeExact(array, 0, 1.0d, 1.0d);
2307             });
2308             // Incorrect arity
2309             checkWMTE(() -> { // 0
2310                 double x = (double) hs.get(am, methodType(double.class)).
2311                     invokeExact();
2312             });
2313             checkWMTE(() -> { // >
2314                 double x = (double) hs.get(am, methodType(double.class, double[].class, int.class, double.class, double.class, Class.class)).
2315                     invokeExact(array, 0, 1.0d, 1.0d, Void.class);
2316             });
2317         }
2318 
2319         for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
2320             // Incorrect argument types
2321             checkNPE(() -> { // null array
2322                 double x = (double) hs.get(am, methodType(double.class, double[].class, int.class, double.class)).
2323                     invokeExact((double[]) null, 0, 1.0d);
2324             });
2325             hs.checkWMTEOrCCE(() -> { // array reference class
2326                 double x = (double) hs.get(am, methodType(double.class, Class.class, int.class, double.class)).
2327                     invokeExact(Void.class, 0, 1.0d);
2328             });
2329             checkWMTE(() -> { // value reference class
2330                 double x = (double) hs.get(am, methodType(double.class, double[].class, int.class, Class.class)).
2331                     invokeExact(array, 0, Void.class);
2332             });
2333             checkWMTE(() -> { // array primitive class
2334                 double x = (double) hs.get(am, methodType(double.class, int.class, int.class, double.class)).
2335                     invokeExact(0, 0, 1.0d);
2336             });
2337             checkWMTE(() -> { // index reference class
2338                 double x = (double) hs.get(am, methodType(double.class, double[].class, Class.class, double.class)).
2339                     invokeExact(array, Void.class, 1.0d);
2340             });
2341             // Incorrect return type
2342             checkWMTE(() -> { // reference class
2343                 Void r = (Void) hs.get(am, methodType(Void.class, double[].class, int.class, double.class)).
2344                     invokeExact(array, 0, 1.0d);
2345             });
2346             checkWMTE(() -> { // primitive class
2347                 boolean x = (boolean) hs.get(am, methodType(boolean.class, double[].class, int.class, double.class)).
2348                     invokeExact(array, 0, 1.0d);
2349             });
2350             // Incorrect arity
2351             checkWMTE(() -> { // 0
2352                 double x = (double) hs.get(am, methodType(double.class)).
2353                     invokeExact();
2354             });
2355             checkWMTE(() -> { // >
2356                 double x = (double) hs.get(am, methodType(double.class, double[].class, int.class, double.class, Class.class)).
2357                     invokeExact(array, 0, 1.0d, Void.class);
2358             });
2359         }
2360 
2361         for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) {
2362             // Incorrect argument types
2363             checkNPE(() -> { // null array
2364                 double x = (double) hs.get(am, methodType(double.class, double[].class, int.class, double.class)).
2365                     invokeExact((double[]) null, 0, 1.0d);
2366             });
2367             hs.checkWMTEOrCCE(() -> { // array reference class
2368                 double x = (double) hs.get(am, methodType(double.class, Class.class, int.class, double.class)).
2369                     invokeExact(Void.class, 0, 1.0d);
2370             });
2371             checkWMTE(() -> { // value reference class
2372                 double x = (double) hs.get(am, methodType(double.class, double[].class, int.class, Class.class)).
2373                     invokeExact(array, 0, Void.class);
2374             });
2375             checkWMTE(() -> { // array primitive class
2376                 double x = (double) hs.get(am, methodType(double.class, int.class, int.class, double.class)).
2377                     invokeExact(0, 0, 1.0d);
2378             });
2379             checkWMTE(() -> { // index reference class
2380                 double x = (double) hs.get(am, methodType(double.class, double[].class, Class.class, double.class)).
2381                     invokeExact(array, Void.class, 1.0d);
2382             });
2383             // Incorrect return type
2384             checkWMTE(() -> { // reference class
2385                 Void r = (Void) hs.get(am, methodType(Void.class, double[].class, int.class, double.class)).
2386                     invokeExact(array, 0, 1.0d);
2387             });
2388             checkWMTE(() -> { // primitive class
2389                 boolean x = (boolean) hs.get(am, methodType(boolean.class, double[].class, int.class, double.class)).
2390                     invokeExact(array, 0, 1.0d);
2391             });
2392             // Incorrect arity
2393             checkWMTE(() -> { // 0
2394                 double x = (double) hs.get(am, methodType(double.class)).
2395                     invokeExact();
2396             });
2397             checkWMTE(() -> { // >
2398                 double x = (double) hs.get(am, methodType(double.class, double[].class, int.class, double.class, Class.class)).
2399                     invokeExact(array, 0, 1.0d, Void.class);
2400             });
2401         }
2402 
2403     }
2404 }

   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 VarHandleTestMethodTypeDouble
  30  * @run testng/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=true -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true VarHandleTestMethodTypeDouble
  31  * @run testng/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=false VarHandleTestMethodTypeDouble
  32  * @run testng/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true VarHandleTestMethodTypeDouble
  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 VarHandleTestMethodTypeDouble extends VarHandleBaseTest {
  50     static final Class<?> type = double.class;
  51 
  52     static final double static_final_v = 1.0d;
  53 
  54     static double static_v = 1.0d;
  55 
  56     final double final_v = 1.0d;
  57 
  58     double v = 1.0d;
  59 
  60     VarHandle vhFinalField;
  61 
  62     VarHandle vhField;
  63 
  64     VarHandle vhStaticField;
  65 
  66     VarHandle vhStaticFinalField;
  67 
  68     VarHandle vhArray;
  69 
  70     @BeforeClass
  71     public void setup() throws Exception {
  72         vhFinalField = MethodHandles.lookup().findVarHandle(
  73                 VarHandleTestMethodTypeDouble.class, "final_v", type);
  74 
  75         vhField = MethodHandles.lookup().findVarHandle(
  76                 VarHandleTestMethodTypeDouble.class, "v", type);
  77 
  78         vhStaticFinalField = MethodHandles.lookup().findStaticVarHandle(
  79             VarHandleTestMethodTypeDouble.class, "static_final_v", type);
  80 
  81         vhStaticField = MethodHandles.lookup().findStaticVarHandle(
  82             VarHandleTestMethodTypeDouble.class, "static_v", type);
  83 
  84         vhArray = MethodHandles.arrayElementVarHandle(double[].class);
  85     }
  86 
  87     @DataProvider
  88     public Object[][] accessTestCaseProvider() throws Exception {
  89         List<AccessTestCase<?>> cases = new ArrayList<>();
  90 
  91         cases.add(new VarHandleAccessTestCase("Instance field",
  92                                               vhField, vh -> testInstanceFieldWrongMethodType(this, vh),
  93                                               false));
  94 
  95         cases.add(new VarHandleAccessTestCase("Static field",
  96                                               vhStaticField, VarHandleTestMethodTypeDouble::testStaticFieldWrongMethodType,
  97                                               false));
  98 
  99         cases.add(new VarHandleAccessTestCase("Array",
 100                                               vhArray, VarHandleTestMethodTypeDouble::testArrayWrongMethodType,
 101                                               false));
 102 

 722         checkWMTE(() -> { // reference class
 723             Void r = (Void) vh.getAndAddRelease(recv, 1.0d);
 724         });
 725         checkWMTE(() -> { // primitive class
 726             boolean x = (boolean) vh.getAndAddRelease(recv, 1.0d);
 727         });
 728         // Incorrect arity
 729         checkWMTE(() -> { // 0
 730             double x = (double) vh.getAndAddRelease();
 731         });
 732         checkWMTE(() -> { // >
 733             double x = (double) vh.getAndAddRelease(recv, 1.0d, Void.class);
 734         });
 735 
 736     }
 737 
 738     static void testInstanceFieldWrongMethodType(VarHandleTestMethodTypeDouble recv, Handles hs) throws Throwable {
 739         for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET)) {
 740             // Incorrect argument types
 741             checkNPE(() -> { // null receiver
 742                 double x = (double) hs.get(am, methodType(type, VarHandleTestMethodTypeDouble.class)).
 743                     invokeExact((VarHandleTestMethodTypeDouble) null);
 744             });
 745             hs.checkWMTEOrCCE(() -> { // receiver reference class
 746                 double x = (double) hs.get(am, methodType(type, Class.class)).
 747                     invokeExact(Void.class);
 748             });
 749             checkWMTE(() -> { // receiver primitive class
 750                 double x = (double) hs.get(am, methodType(type, int.class)).
 751                     invokeExact(0);
 752             });
 753             // Incorrect return type
 754             checkWMTE(() -> { // reference class
 755                 Void x = (Void) hs.get(am, methodType(Void.class, VarHandleTestMethodTypeDouble.class)).
 756                     invokeExact(recv);
 757             });
 758             checkWMTE(() -> { // primitive class
 759                 boolean x = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeDouble.class)).
 760                     invokeExact(recv);
 761             });
 762             // Incorrect arity
 763             checkWMTE(() -> { // 0
 764                 double x = (double) hs.get(am, methodType(type)).
 765                     invokeExact();
 766             });
 767             checkWMTE(() -> { // >
 768                 double x = (double) hs.get(am, methodType(type, VarHandleTestMethodTypeDouble.class, Class.class)).
 769                     invokeExact(recv, Void.class);
 770             });
 771         }
 772 
 773         for (TestAccessMode am : testAccessModesOfType(TestAccessType.SET)) {
 774             // Incorrect argument types
 775             checkNPE(() -> { // null receiver
 776                 hs.get(am, methodType(void.class, VarHandleTestMethodTypeDouble.class, type)).
 777                     invokeExact((VarHandleTestMethodTypeDouble) null, 1.0d);
 778             });
 779             hs.checkWMTEOrCCE(() -> { // receiver reference class
 780                 hs.get(am, methodType(void.class, Class.class, type)).
 781                     invokeExact(Void.class, 1.0d);
 782             });
 783             checkWMTE(() -> { // value reference class
 784                 hs.get(am, methodType(void.class, VarHandleTestMethodTypeDouble.class, Class.class)).
 785                     invokeExact(recv, Void.class);
 786             });
 787             checkWMTE(() -> { // receiver primitive class
 788                 hs.get(am, methodType(void.class, int.class, type)).
 789                     invokeExact(0, 1.0d);
 790             });
 791             // Incorrect arity
 792             checkWMTE(() -> { // 0
 793                 hs.get(am, methodType(void.class)).
 794                     invokeExact();
 795             });
 796             checkWMTE(() -> { // >
 797                 hs.get(am, methodType(void.class, VarHandleTestMethodTypeDouble.class, type, Class.class)).
 798                     invokeExact(recv, 1.0d, Void.class);
 799             });
 800         }
 801 
 802         for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
 803             // Incorrect argument types
 804             checkNPE(() -> { // null receiver
 805                 boolean r = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeDouble.class, type, type)).
 806                     invokeExact((VarHandleTestMethodTypeDouble) null, 1.0d, 1.0d);
 807             });
 808             hs.checkWMTEOrCCE(() -> { // receiver reference class
 809                 boolean r = (boolean) hs.get(am, methodType(boolean.class, Class.class, type, type)).
 810                     invokeExact(Void.class, 1.0d, 1.0d);
 811             });
 812             checkWMTE(() -> { // expected reference class
 813                 boolean r = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeDouble.class, Class.class, type)).
 814                     invokeExact(recv, Void.class, 1.0d);
 815             });
 816             checkWMTE(() -> { // actual reference class
 817                 boolean r = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeDouble.class, type, Class.class)).
 818                     invokeExact(recv, 1.0d, Void.class);
 819             });
 820             checkWMTE(() -> { // receiver primitive class
 821                 boolean r = (boolean) hs.get(am, methodType(boolean.class, int.class , type, type)).
 822                     invokeExact(0, 1.0d, 1.0d);
 823             });
 824             // Incorrect arity
 825             checkWMTE(() -> { // 0
 826                 boolean r = (boolean) hs.get(am, methodType(boolean.class)).
 827                     invokeExact();
 828             });
 829             checkWMTE(() -> { // >
 830                 boolean r = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeDouble.class, type, type, Class.class)).
 831                     invokeExact(recv, 1.0d, 1.0d, Void.class);
 832             });
 833         }
 834 
 835         for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
 836             checkNPE(() -> { // null receiver
 837                 double x = (double) hs.get(am, methodType(type, VarHandleTestMethodTypeDouble.class, type, type)).
 838                     invokeExact((VarHandleTestMethodTypeDouble) null, 1.0d, 1.0d);
 839             });
 840             hs.checkWMTEOrCCE(() -> { // receiver reference class
 841                 double x = (double) hs.get(am, methodType(type, Class.class, type, type)).
 842                     invokeExact(Void.class, 1.0d, 1.0d);
 843             });
 844             checkWMTE(() -> { // expected reference class
 845                 double x = (double) hs.get(am, methodType(type, VarHandleTestMethodTypeDouble.class, Class.class, type)).
 846                     invokeExact(recv, Void.class, 1.0d);
 847             });
 848             checkWMTE(() -> { // actual reference class
 849                 double x = (double) hs.get(am, methodType(type, VarHandleTestMethodTypeDouble.class, type, Class.class)).
 850                     invokeExact(recv, 1.0d, Void.class);
 851             });
 852             checkWMTE(() -> { // reciever primitive class
 853                 double x = (double) hs.get(am, methodType(type, int.class , type, type)).
 854                     invokeExact(0, 1.0d, 1.0d);
 855             });
 856             // Incorrect return type
 857             checkWMTE(() -> { // reference class
 858                 Void r = (Void) hs.get(am, methodType(Void.class, VarHandleTestMethodTypeDouble.class , type, type)).
 859                     invokeExact(recv, 1.0d, 1.0d);
 860             });
 861             checkWMTE(() -> { // primitive class
 862                 boolean x = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeDouble.class , type, type)).
 863                     invokeExact(recv, 1.0d, 1.0d);
 864             });
 865             // Incorrect arity
 866             checkWMTE(() -> { // 0
 867                 double x = (double) hs.get(am, methodType(type)).
 868                     invokeExact();
 869             });
 870             checkWMTE(() -> { // >
 871                 double x = (double) hs.get(am, methodType(type, VarHandleTestMethodTypeDouble.class, type, type, Class.class)).
 872                     invokeExact(recv, 1.0d, 1.0d, Void.class);
 873             });
 874         }
 875 
 876         for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
 877             checkNPE(() -> { // null receiver
 878                 double x = (double) hs.get(am, methodType(type, VarHandleTestMethodTypeDouble.class, type)).
 879                     invokeExact((VarHandleTestMethodTypeDouble) null, 1.0d);
 880             });
 881             hs.checkWMTEOrCCE(() -> { // receiver reference class
 882                 double x = (double) hs.get(am, methodType(type, Class.class, type)).
 883                     invokeExact(Void.class, 1.0d);
 884             });
 885             checkWMTE(() -> { // value reference class
 886                 double x = (double) hs.get(am, methodType(type, VarHandleTestMethodTypeDouble.class, Class.class)).
 887                     invokeExact(recv, Void.class);
 888             });
 889             checkWMTE(() -> { // reciever primitive class
 890                 double x = (double) hs.get(am, methodType(type, int.class, type)).
 891                     invokeExact(0, 1.0d);
 892             });
 893             // Incorrect return type
 894             checkWMTE(() -> { // reference class
 895                 Void r = (Void) hs.get(am, methodType(Void.class, VarHandleTestMethodTypeDouble.class, type)).
 896                     invokeExact(recv, 1.0d);
 897             });
 898             checkWMTE(() -> { // primitive class
 899                 boolean x = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeDouble.class, type)).
 900                     invokeExact(recv, 1.0d);
 901             });
 902             // Incorrect arity
 903             checkWMTE(() -> { // 0
 904                 double x = (double) hs.get(am, methodType(type)).
 905                     invokeExact();
 906             });
 907             checkWMTE(() -> { // >
 908                 double x = (double) hs.get(am, methodType(type, VarHandleTestMethodTypeDouble.class, type)).
 909                     invokeExact(recv, 1.0d, Void.class);
 910             });
 911         }
 912 
 913         for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) {
 914             checkNPE(() -> { // null receiver
 915                 double x = (double) hs.get(am, methodType(type, VarHandleTestMethodTypeDouble.class, type)).
 916                     invokeExact((VarHandleTestMethodTypeDouble) null, 1.0d);
 917             });
 918             hs.checkWMTEOrCCE(() -> { // receiver reference class
 919                 double x = (double) hs.get(am, methodType(type, Class.class, type)).
 920                     invokeExact(Void.class, 1.0d);
 921             });
 922             checkWMTE(() -> { // value reference class
 923                 double x = (double) hs.get(am, methodType(type, VarHandleTestMethodTypeDouble.class, Class.class)).
 924                     invokeExact(recv, Void.class);
 925             });
 926             checkWMTE(() -> { // reciever primitive class
 927                 double x = (double) hs.get(am, methodType(type, int.class, type)).
 928                     invokeExact(0, 1.0d);
 929             });
 930             // Incorrect return type
 931             checkWMTE(() -> { // reference class
 932                 Void r = (Void) hs.get(am, methodType(Void.class, VarHandleTestMethodTypeDouble.class, type)).
 933                     invokeExact(recv, 1.0d);
 934             });
 935             checkWMTE(() -> { // primitive class
 936                 boolean x = (boolean) hs.get(am, methodType(boolean.class, VarHandleTestMethodTypeDouble.class, type)).
 937                     invokeExact(recv, 1.0d);
 938             });
 939             // Incorrect arity
 940             checkWMTE(() -> { // 0
 941                 double x = (double) hs.get(am, methodType(type)).
 942                     invokeExact();
 943             });
 944             checkWMTE(() -> { // >
 945                 double x = (double) hs.get(am, methodType(type, VarHandleTestMethodTypeDouble.class, type)).
 946                     invokeExact(recv, 1.0d, Void.class);
 947             });
 948         }
 949 
 950     }
 951 
 952 
 953     static void testStaticFieldWrongMethodType(VarHandle vh) throws Throwable {
 954         // Get
 955         // Incorrect return type
 956         checkWMTE(() -> { // reference class
 957             Void x = (Void) vh.get();
 958         });
 959         checkWMTE(() -> { // primitive class
 960             boolean x = (boolean) vh.get();
 961         });
 962         // Incorrect arity
 963         checkWMTE(() -> { // >
 964             double x = (double) vh.get(Void.class);
 965         });

1357                     invokeExact();
1358             });
1359             // Incorrect arity
1360             checkWMTE(() -> { // >
1361                 double x = (double) hs.get(am, methodType(Class.class)).
1362                     invokeExact(Void.class);
1363             });
1364         }
1365 
1366         for (TestAccessMode am : testAccessModesOfType(TestAccessType.SET)) {
1367             checkWMTE(() -> { // value reference class
1368                 hs.get(am, methodType(void.class, Class.class)).
1369                     invokeExact(Void.class);
1370             });
1371             // Incorrect arity
1372             checkWMTE(() -> { // 0
1373                 hs.get(am, methodType(void.class)).
1374                     invokeExact();
1375             });
1376             checkWMTE(() -> { // >
1377                 hs.get(am, methodType(void.class, type, Class.class)).
1378                     invokeExact(1.0d, Void.class);
1379             });
1380         }
1381         for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
1382             // Incorrect argument types
1383             checkWMTE(() -> { // expected reference class
1384                 boolean r = (boolean) hs.get(am, methodType(boolean.class, Class.class, type)).
1385                     invokeExact(Void.class, 1.0d);
1386             });
1387             checkWMTE(() -> { // actual reference class
1388                 boolean r = (boolean) hs.get(am, methodType(boolean.class, type, Class.class)).
1389                     invokeExact(1.0d, Void.class);
1390             });
1391             // Incorrect arity
1392             checkWMTE(() -> { // 0
1393                 boolean r = (boolean) hs.get(am, methodType(boolean.class)).
1394                     invokeExact();
1395             });
1396             checkWMTE(() -> { // >
1397                 boolean r = (boolean) hs.get(am, methodType(boolean.class, type, type, Class.class)).
1398                     invokeExact(1.0d, 1.0d, Void.class);
1399             });
1400         }
1401 
1402         for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
1403             // Incorrect argument types
1404             checkWMTE(() -> { // expected reference class
1405                 double x = (double) hs.get(am, methodType(type, Class.class, type)).
1406                     invokeExact(Void.class, 1.0d);
1407             });
1408             checkWMTE(() -> { // actual reference class
1409                 double x = (double) hs.get(am, methodType(type, type, Class.class)).
1410                     invokeExact(1.0d, Void.class);
1411             });
1412             // Incorrect return type
1413             checkWMTE(() -> { // reference class
1414                 Void r = (Void) hs.get(am, methodType(Void.class, type, type)).
1415                     invokeExact(1.0d, 1.0d);
1416             });
1417             checkWMTE(() -> { // primitive class
1418                 boolean x = (boolean) hs.get(am, methodType(boolean.class, type, type)).
1419                     invokeExact(1.0d, 1.0d);
1420             });
1421             // Incorrect arity
1422             checkWMTE(() -> { // 0
1423                 double x = (double) hs.get(am, methodType(type)).
1424                     invokeExact();
1425             });
1426             checkWMTE(() -> { // >
1427                 double x = (double) hs.get(am, methodType(type, type, type, Class.class)).
1428                     invokeExact(1.0d, 1.0d, Void.class);
1429             });
1430         }
1431 
1432         for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
1433             // Incorrect argument types
1434             checkWMTE(() -> { // value reference class
1435                 double x = (double) hs.get(am, methodType(type, Class.class)).
1436                     invokeExact(Void.class);
1437             });
1438             // Incorrect return type
1439             checkWMTE(() -> { // reference class
1440                 Void r = (Void) hs.get(am, methodType(Void.class, type)).
1441                     invokeExact(1.0d);
1442             });
1443             checkWMTE(() -> { // primitive class
1444                 boolean x = (boolean) hs.get(am, methodType(boolean.class, type)).
1445                     invokeExact(1.0d);
1446             });
1447             // Incorrect arity
1448             checkWMTE(() -> { // 0
1449                 double x = (double) hs.get(am, methodType(type)).
1450                     invokeExact();
1451             });
1452             checkWMTE(() -> { // >
1453                 double x = (double) hs.get(am, methodType(type, type, Class.class)).
1454                     invokeExact(1.0d, Void.class);
1455             });
1456         }
1457 
1458         for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) {
1459             // Incorrect argument types
1460             checkWMTE(() -> { // value reference class
1461                 double x = (double) hs.get(am, methodType(type, Class.class)).
1462                     invokeExact(Void.class);
1463             });
1464             // Incorrect return type
1465             checkWMTE(() -> { // reference class
1466                 Void r = (Void) hs.get(am, methodType(Void.class, type)).
1467                     invokeExact(1.0d);
1468             });
1469             checkWMTE(() -> { // primitive class
1470                 boolean x = (boolean) hs.get(am, methodType(boolean.class, type)).
1471                     invokeExact(1.0d);
1472             });
1473             // Incorrect arity
1474             checkWMTE(() -> { // 0
1475                 double x = (double) hs.get(am, methodType(type)).
1476                     invokeExact();
1477             });
1478             checkWMTE(() -> { // >
1479                 double x = (double) hs.get(am, methodType(type, type, Class.class)).
1480                     invokeExact(1.0d, Void.class);
1481             });
1482         }
1483 
1484     }
1485 
1486 
1487     static void testArrayWrongMethodType(VarHandle vh) throws Throwable {
1488         double[] array = new double[10];
1489         Arrays.fill(array, 1.0d);
1490 
1491         // Get
1492         // Incorrect argument types
1493         checkNPE(() -> { // null array
1494             double x = (double) vh.get(null, 0);
1495         });
1496         checkCCE(() -> { // array reference class
1497             double x = (double) vh.get(Void.class, 0);
1498         });
1499         checkWMTE(() -> { // array primitive class

2153         checkWMTE(() -> { // primitive class
2154             boolean x = (boolean) vh.getAndAddRelease(array, 0, 1.0d);
2155         });
2156         // Incorrect arity
2157         checkWMTE(() -> { // 0
2158             double x = (double) vh.getAndAddRelease();
2159         });
2160         checkWMTE(() -> { // >
2161             double x = (double) vh.getAndAddRelease(array, 0, 1.0d, Void.class);
2162         });
2163 
2164     }
2165 
2166     static void testArrayWrongMethodType(Handles hs) throws Throwable {
2167         double[] array = new double[10];
2168         Arrays.fill(array, 1.0d);
2169 
2170         for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET)) {
2171             // Incorrect argument types
2172             checkNPE(() -> { // null array
2173                 double x = (double) hs.get(am, methodType(type, double[].class, int.class)).
2174                     invokeExact((double[]) null, 0);
2175             });
2176             hs.checkWMTEOrCCE(() -> { // array reference class
2177                 double x = (double) hs.get(am, methodType(type, Class.class, int.class)).
2178                     invokeExact(Void.class, 0);
2179             });
2180             checkWMTE(() -> { // array primitive class
2181                 double x = (double) hs.get(am, methodType(type, int.class, int.class)).
2182                     invokeExact(0, 0);
2183             });
2184             checkWMTE(() -> { // index reference class
2185                 double x = (double) hs.get(am, methodType(type, double[].class, Class.class)).
2186                     invokeExact(array, Void.class);
2187             });
2188             // Incorrect return type
2189             checkWMTE(() -> { // reference class
2190                 Void x = (Void) hs.get(am, methodType(Void.class, double[].class, int.class)).
2191                     invokeExact(array, 0);
2192             });
2193             checkWMTE(() -> { // primitive class
2194                 boolean x = (boolean) hs.get(am, methodType(boolean.class, double[].class, int.class)).
2195                     invokeExact(array, 0);
2196             });
2197             // Incorrect arity
2198             checkWMTE(() -> { // 0
2199                 double x = (double) hs.get(am, methodType(type)).
2200                     invokeExact();
2201             });
2202             checkWMTE(() -> { // >
2203                 double x = (double) hs.get(am, methodType(type, double[].class, int.class, Class.class)).
2204                     invokeExact(array, 0, Void.class);
2205             });
2206         }
2207 
2208         for (TestAccessMode am : testAccessModesOfType(TestAccessType.SET)) {
2209             // Incorrect argument types
2210             checkNPE(() -> { // null array
2211                 hs.get(am, methodType(void.class, double[].class, int.class, type)).
2212                     invokeExact((double[]) null, 0, 1.0d);
2213             });
2214             hs.checkWMTEOrCCE(() -> { // array reference class
2215                 hs.get(am, methodType(void.class, Class.class, int.class, type)).
2216                     invokeExact(Void.class, 0, 1.0d);
2217             });
2218             checkWMTE(() -> { // value reference class
2219                 hs.get(am, methodType(void.class, double[].class, int.class, Class.class)).
2220                     invokeExact(array, 0, Void.class);
2221             });
2222             checkWMTE(() -> { // receiver primitive class
2223                 hs.get(am, methodType(void.class, int.class, int.class, type)).
2224                     invokeExact(0, 0, 1.0d);
2225             });
2226             checkWMTE(() -> { // index reference class
2227                 hs.get(am, methodType(void.class, double[].class, Class.class, type)).
2228                     invokeExact(array, Void.class, 1.0d);
2229             });
2230             // Incorrect arity
2231             checkWMTE(() -> { // 0
2232                 hs.get(am, methodType(void.class)).
2233                     invokeExact();
2234             });
2235             checkWMTE(() -> { // >
2236                 hs.get(am, methodType(void.class, double[].class, int.class, Class.class)).
2237                     invokeExact(array, 0, 1.0d, Void.class);
2238             });
2239         }
2240         for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
2241             // Incorrect argument types
2242             checkNPE(() -> { // null receiver
2243                 boolean r = (boolean) hs.get(am, methodType(boolean.class, double[].class, int.class, type, type)).
2244                     invokeExact((double[]) null, 0, 1.0d, 1.0d);
2245             });
2246             hs.checkWMTEOrCCE(() -> { // receiver reference class
2247                 boolean r = (boolean) hs.get(am, methodType(boolean.class, Class.class, int.class, type, type)).
2248                     invokeExact(Void.class, 0, 1.0d, 1.0d);
2249             });
2250             checkWMTE(() -> { // expected reference class
2251                 boolean r = (boolean) hs.get(am, methodType(boolean.class, double[].class, int.class, Class.class, type)).
2252                     invokeExact(array, 0, Void.class, 1.0d);
2253             });
2254             checkWMTE(() -> { // actual reference class
2255                 boolean r = (boolean) hs.get(am, methodType(boolean.class, double[].class, int.class, type, Class.class)).
2256                     invokeExact(array, 0, 1.0d, Void.class);
2257             });
2258             checkWMTE(() -> { // receiver primitive class
2259                 boolean r = (boolean) hs.get(am, methodType(boolean.class, int.class, int.class, type, type)).
2260                     invokeExact(0, 0, 1.0d, 1.0d);
2261             });
2262             checkWMTE(() -> { // index reference class
2263                 boolean r = (boolean) hs.get(am, methodType(boolean.class, double[].class, Class.class, type, type)).
2264                     invokeExact(array, Void.class, 1.0d, 1.0d);
2265             });
2266             // Incorrect arity
2267             checkWMTE(() -> { // 0
2268                 boolean r = (boolean) hs.get(am, methodType(boolean.class)).
2269                     invokeExact();
2270             });
2271             checkWMTE(() -> { // >
2272                 boolean r = (boolean) hs.get(am, methodType(boolean.class, double[].class, int.class, type, type, Class.class)).
2273                     invokeExact(array, 0, 1.0d, 1.0d, Void.class);
2274             });
2275         }
2276 
2277         for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
2278             // Incorrect argument types
2279             checkNPE(() -> { // null receiver
2280                 double x = (double) hs.get(am, methodType(type, double[].class, int.class, type, type)).
2281                     invokeExact((double[]) null, 0, 1.0d, 1.0d);
2282             });
2283             hs.checkWMTEOrCCE(() -> { // array reference class
2284                 double x = (double) hs.get(am, methodType(type, Class.class, int.class, type, type)).
2285                     invokeExact(Void.class, 0, 1.0d, 1.0d);
2286             });
2287             checkWMTE(() -> { // expected reference class
2288                 double x = (double) hs.get(am, methodType(type, double[].class, int.class, Class.class, type)).
2289                     invokeExact(array, 0, Void.class, 1.0d);
2290             });
2291             checkWMTE(() -> { // actual reference class
2292                 double x = (double) hs.get(am, methodType(type, double[].class, int.class, type, Class.class)).
2293                     invokeExact(array, 0, 1.0d, Void.class);
2294             });
2295             checkWMTE(() -> { // array primitive class
2296                 double x = (double) hs.get(am, methodType(type, int.class, int.class, type, type)).
2297                     invokeExact(0, 0, 1.0d, 1.0d);
2298             });
2299             checkWMTE(() -> { // index reference class
2300                 double x = (double) hs.get(am, methodType(type, double[].class, Class.class, type, type)).
2301                     invokeExact(array, Void.class, 1.0d, 1.0d);
2302             });
2303             // Incorrect return type
2304             checkWMTE(() -> { // reference class
2305                 Void r = (Void) hs.get(am, methodType(Void.class, double[].class, int.class, type, type)).
2306                     invokeExact(array, 0, 1.0d, 1.0d);
2307             });
2308             checkWMTE(() -> { // primitive class
2309                 boolean x = (boolean) hs.get(am, methodType(boolean.class, double[].class, int.class, type, type)).
2310                     invokeExact(array, 0, 1.0d, 1.0d);
2311             });
2312             // Incorrect arity
2313             checkWMTE(() -> { // 0
2314                 double x = (double) hs.get(am, methodType(type)).
2315                     invokeExact();
2316             });
2317             checkWMTE(() -> { // >
2318                 double x = (double) hs.get(am, methodType(type, double[].class, int.class, type, type, Class.class)).
2319                     invokeExact(array, 0, 1.0d, 1.0d, Void.class);
2320             });
2321         }
2322 
2323         for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
2324             // Incorrect argument types
2325             checkNPE(() -> { // null array
2326                 double x = (double) hs.get(am, methodType(type, double[].class, int.class, type)).
2327                     invokeExact((double[]) null, 0, 1.0d);
2328             });
2329             hs.checkWMTEOrCCE(() -> { // array reference class
2330                 double x = (double) hs.get(am, methodType(type, Class.class, int.class, type)).
2331                     invokeExact(Void.class, 0, 1.0d);
2332             });
2333             checkWMTE(() -> { // value reference class
2334                 double x = (double) hs.get(am, methodType(type, double[].class, int.class, Class.class)).
2335                     invokeExact(array, 0, Void.class);
2336             });
2337             checkWMTE(() -> { // array primitive class
2338                 double x = (double) hs.get(am, methodType(type, int.class, int.class, type)).
2339                     invokeExact(0, 0, 1.0d);
2340             });
2341             checkWMTE(() -> { // index reference class
2342                 double x = (double) hs.get(am, methodType(type, double[].class, Class.class, type)).
2343                     invokeExact(array, Void.class, 1.0d);
2344             });
2345             // Incorrect return type
2346             checkWMTE(() -> { // reference class
2347                 Void r = (Void) hs.get(am, methodType(Void.class, double[].class, int.class, type)).
2348                     invokeExact(array, 0, 1.0d);
2349             });
2350             checkWMTE(() -> { // primitive class
2351                 boolean x = (boolean) hs.get(am, methodType(boolean.class, double[].class, int.class, type)).
2352                     invokeExact(array, 0, 1.0d);
2353             });
2354             // Incorrect arity
2355             checkWMTE(() -> { // 0
2356                 double x = (double) hs.get(am, methodType(type)).
2357                     invokeExact();
2358             });
2359             checkWMTE(() -> { // >
2360                 double x = (double) hs.get(am, methodType(type, double[].class, int.class, type, Class.class)).
2361                     invokeExact(array, 0, 1.0d, Void.class);
2362             });
2363         }
2364 
2365         for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) {
2366             // Incorrect argument types
2367             checkNPE(() -> { // null array
2368                 double x = (double) hs.get(am, methodType(type, double[].class, int.class, type)).
2369                     invokeExact((double[]) null, 0, 1.0d);
2370             });
2371             hs.checkWMTEOrCCE(() -> { // array reference class
2372                 double x = (double) hs.get(am, methodType(type, Class.class, int.class, type)).
2373                     invokeExact(Void.class, 0, 1.0d);
2374             });
2375             checkWMTE(() -> { // value reference class
2376                 double x = (double) hs.get(am, methodType(type, double[].class, int.class, Class.class)).
2377                     invokeExact(array, 0, Void.class);
2378             });
2379             checkWMTE(() -> { // array primitive class
2380                 double x = (double) hs.get(am, methodType(type, int.class, int.class, type)).
2381                     invokeExact(0, 0, 1.0d);
2382             });
2383             checkWMTE(() -> { // index reference class
2384                 double x = (double) hs.get(am, methodType(type, double[].class, Class.class, type)).
2385                     invokeExact(array, Void.class, 1.0d);
2386             });
2387             // Incorrect return type
2388             checkWMTE(() -> { // reference class
2389                 Void r = (Void) hs.get(am, methodType(Void.class, double[].class, int.class, type)).
2390                     invokeExact(array, 0, 1.0d);
2391             });
2392             checkWMTE(() -> { // primitive class
2393                 boolean x = (boolean) hs.get(am, methodType(boolean.class, double[].class, int.class, type)).
2394                     invokeExact(array, 0, 1.0d);
2395             });
2396             // Incorrect arity
2397             checkWMTE(() -> { // 0
2398                 double x = (double) hs.get(am, methodType(type)).
2399                     invokeExact();
2400             });
2401             checkWMTE(() -> { // >
2402                 double x = (double) hs.get(am, methodType(type, double[].class, int.class, type, Class.class)).
2403                     invokeExact(array, 0, 1.0d, Void.class);
2404             });
2405         }
2406 
2407     }
2408 }
< prev index next >