< prev index next >

src/java.base/share/classes/jdk/experimental/value/ValueType.java

Print this page
rev 17246 : [mq]: findWither-access

@@ -277,15 +277,20 @@
 
             result = MethodHandleBuilder.loadCode(valueLookup, mhName("wither$" + name), MethodType.methodType(valueClass(), valueClass(), type),
                     C -> C.vload(0).load(1).vwithfield(valueClass(), name, fieldType).vreturn());
             handleMap.put(key, result);
         }
-        // @@@ special access check for read/write access
-        //force access-check
-        lookup.findGetter(boxClass(), name, type);
+
+        // Allow access if the lookup class is the VCC or DVT and the lookup
+        // has private access
+        Class<?> lc = lookup.lookupClass();
+        if (lookup.hasPrivateAccess() && (valueClass() == lc || boxClass() == lc)) {
         return result;
     }
+        throw new IllegalAccessException(String.format("Class %s does not have vwithfield access to field %s.%s",
+                                                       lc.getName(), boxClass().getName(), name));
+    }
 
     public MethodHandle unbox() {
         ValueHandleKey key = ValueHandleKind.UNBOX.key();
         MethodHandle result = handleMap.get(key);
         if (result == null) {
< prev index next >