< prev index next >

test/jdk/java/lang/invoke/VarHandles/accessibility/TestFieldLookupAccessibility.java

Print this page

        

@@ -108,10 +108,14 @@
         },
         MH_UNREFLECT_SETTER_ACCESSIBLE() {
             Object lookup(MethodHandles.Lookup l, Field f) throws Exception {
                 return l.unreflectSetter(cloneAndSetAccessible(f));
             }
+
+            boolean isAccessible(Field f) {
+                return !(Modifier.isStatic(f.getModifiers()) && Modifier.isFinal(f.getModifiers()));
+            }
         },
         VH() {
             Object lookup(MethodHandles.Lookup l, Field f) throws Exception {
                 return l.findVarHandle(f.getDeclaringClass(), f.getName(), f.getType());
             }

@@ -208,10 +212,12 @@
                     fl != FieldLookup.MH_UNREFLECT_SETTER_ACCESSIBLE) {
                     Assert.assertEquals(actualFieldNames, expected, "No accessibility failures:");
                 }
             }
             else {
+                //If this is an MH_UNREFLECT_SETTER_ACCESSIBLE test, then we only expect the static final fields to cause exceptions.
+                if (fl != FieldLookup.MH_UNREFLECT_SETTER_ACCESSIBLE && actualFieldNames.stream().anyMatch(s->!(s.contains("static")&&(s.contains("final")))))
                 Assert.assertEquals(actualFieldNames, expected, "Accessibility failures differ:");
             }
         }
         else {
             if (!actual.values().stream().allMatch(IllegalAccessException.class::isInstance)) {
< prev index next >