< prev index next >

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

Print this page
*** 19,10 ***
--- 19,12 ---
   * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   * or visit www.oracle.com if you need additional information or have any
   * questions.
   */
  
+ // -- This file was mechanically generated: Do not edit! -- //
+ 
  /*
   * @test
   * @run testng/othervm -Diters=20000 VarHandleTestMethodHandleAccessChar
   */
  

*** 37,10 ***
--- 39,12 ---
  import java.util.List;
  
  import static org.testng.Assert.*;
  
  public class VarHandleTestMethodHandleAccessChar extends VarHandleBaseTest {
+     static final Class<?> type = char.class;
+ 
      static final char static_final_v = '\u0123';
  
      static char static_v;
  
      final char final_v = '\u0123';

*** 55,25 ***
  
      VarHandle vhStaticFinalField;
  
      VarHandle vhArray;
  
      @BeforeClass
      public void setup() throws Exception {
          vhFinalField = MethodHandles.lookup().findVarHandle(
!                 VarHandleTestMethodHandleAccessChar.class, "final_v", char.class);
  
          vhField = MethodHandles.lookup().findVarHandle(
!                 VarHandleTestMethodHandleAccessChar.class, "v", char.class);
  
          vhStaticFinalField = MethodHandles.lookup().findStaticVarHandle(
!             VarHandleTestMethodHandleAccessChar.class, "static_final_v", char.class);
  
          vhStaticField = MethodHandles.lookup().findStaticVarHandle(
!             VarHandleTestMethodHandleAccessChar.class, "static_v", char.class);
  
          vhArray = MethodHandles.arrayElementVarHandle(char[].class);
      }
  
  
      @DataProvider
      public Object[][] accessTestCaseProvider() throws Exception {
--- 59,30 ---
  
      VarHandle vhStaticFinalField;
  
      VarHandle vhArray;
  
+     VarHandle vhValueTypeField;
+ 
      @BeforeClass
      public void setup() throws Exception {
          vhFinalField = MethodHandles.lookup().findVarHandle(
!                 VarHandleTestMethodHandleAccessChar.class, "final_v", type);
  
          vhField = MethodHandles.lookup().findVarHandle(
!                 VarHandleTestMethodHandleAccessChar.class, "v", type);
  
          vhStaticFinalField = MethodHandles.lookup().findStaticVarHandle(
!             VarHandleTestMethodHandleAccessChar.class, "static_final_v", type);
  
          vhStaticField = MethodHandles.lookup().findStaticVarHandle(
!             VarHandleTestMethodHandleAccessChar.class, "static_v", type);
  
          vhArray = MethodHandles.arrayElementVarHandle(char[].class);
+ 
+         vhValueTypeField = MethodHandles.lookup().findVarHandle(
+                     Value.class, "char_v", type);
      }
  
  
      @DataProvider
      public Object[][] accessTestCaseProvider() throws Exception {

*** 98,10 ***
--- 107,15 ---
                                                       vhArray, f, VarHandleTestMethodHandleAccessChar::testArrayUnsupported,
                                                       false));
              cases.add(new MethodHandleAccessTestCase("Array index out of bounds",
                                                       vhArray, f, VarHandleTestMethodHandleAccessChar::testArrayIndexOutOfBounds,
                                                       false));
+         cases.add(new MethodHandleAccessTestCase("Value type field",
+                                                  vhValueTypeField, f, hs -> testValueTypeField(Value.getInstance(), hs)));
+         cases.add(new MethodHandleAccessTestCase("Value type field unsupported",
+                                                  vhValueTypeField, f, hs -> testValueTypeFieldUnsupported(Value.getInstance(), hs),
+                                                  false));
          }
  
          // Work around issue with jtreg summary reporting which truncates
          // the String result of Object.toString to 30 characters, hence
          // the first dummy argument

*** 371,10 ***
--- 385,28 ---
      static void testInstanceFieldUnsupported(VarHandleTestMethodHandleAccessChar recv, Handles hs) throws Throwable {
  
  
      }
  
+     static void testValueTypeField(Value recv, Handles hs) throws Throwable {
+         // Plain
+         {
+             char x = (char) hs.get(TestAccessMode.GET).invokeExact(recv);
+             assertEquals(x, '\u0123', "get char value");
+         }
+     }
+ 
+     static void testValueTypeFieldUnsupported(Value recv, Handles hs) throws Throwable {
+         // Plain
+         for (TestAccessMode am : testAccessModesOfType(TestAccessType.SET)) {
+             checkUOE(am, () -> {
+                 hs.get(am).invokeExact(recv, '\u0123');
+             });
+         }
+ 
+ 
+     }
  
      static void testStaticField(Handles hs) throws Throwable {
          // Plain
          {
              hs.get(TestAccessMode.SET).invokeExact('\u0123');
< prev index next >