< prev index next >

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

Print this page

        

*** 20,30 **** * or visit www.oracle.com if you need additional information or have any * questions. */ /* @test ! * @bug 8152645 * @summary test field lookup accessibility of MethodHandles and VarHandles * @compile TestFieldLookupAccessibility.java * pkg/A.java pkg/B_extends_A.java pkg/C.java * pkg/subpkg/B_extends_A.java pkg/subpkg/C.java * @run testng/othervm TestFieldLookupAccessibility --- 20,30 ---- * or visit www.oracle.com if you need additional information or have any * questions. */ /* @test ! * @bug 8152645 8216558 * @summary test field lookup accessibility of MethodHandles and VarHandles * @compile TestFieldLookupAccessibility.java * pkg/A.java pkg/B_extends_A.java pkg/C.java * pkg/subpkg/B_extends_A.java pkg/subpkg/C.java * @run testng/othervm TestFieldLookupAccessibility
*** 108,117 **** --- 108,121 ---- }, 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,217 **** --- 212,223 ---- 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 >