--- old/test/jdk/java/lang/invoke/MethodHandlesGeneralTest.java 2019-03-07 15:05:29.000000000 +0000 +++ new/test/jdk/java/lang/invoke/MethodHandlesGeneralTest.java 2019-03-07 15:05:28.000000000 +0000 @@ -634,7 +634,7 @@ public void testGetter(int testMode) throws Throwable { Lookup lookup = PRIVATE; // FIXME: test more lookups than this one - for (Object[] c : HasFields.CASES) { + for (Object[] c : HasFields.cases(testMode)) { boolean positive = (c[1] != Error.class); testGetter(positive, lookup, c[0], c[1], testMode); if (positive) @@ -723,15 +723,19 @@ if (verbosity >= 5) ex.printStackTrace(System.out); } if (verbosity >= 3) - System.out.println("find"+(isStatic?"Static":"")+(isGetter?"Getter":"Setter")+" "+fclass.getName()+"."+fname+"/"+ftype - +" => "+mh - +(noAccess == null ? "" : " !! "+noAccess)); + System.out.format("%s%s %s.%s/%s => %s %s%n", + (testMode0 & TEST_UNREFLECT) != 0 + ? "unreflect" + : "find" + ((testMode0 & TEST_FIND_STATIC) != 0 ? "Static" : ""), + (isGetter ? "Getter" : "Setter"), + fclass.getName(), fname, ftype, mh, + (noAccess == null ? "" : " !! "+noAccess)); + if (!positive && noAccess != null) return; if (positive && !testNPE && noAccess != null) throw new RuntimeException(noAccess); assertEquals(positive0 ? "positive test" : "negative test erroneously passed", positive0, mh != null); if (!positive && !testNPE) return; // negative access test failed as expected assertEquals((isStatic ? 0 : 1)+(isGetter ? 0 : 1), mh.type().parameterCount()); - assertSame(mh.type(), expType); //assertNameStringContains(mh, fname); // This does not hold anymore with LFs HasFields fields = new HasFields(); @@ -755,6 +759,8 @@ assertEquals(f.get(fields), value); // clean to start with } Throwable caughtEx = null; + boolean writeAccess = !Modifier.isFinal(f.getModifiers()) || + (!Modifier.isStatic(f.getModifiers()) && f.isAccessible()); if (isGetter) { Object expValue = value; for (int i = 0; i <= 1; i++) { @@ -778,8 +784,7 @@ } } assertEquals(sawValue, expValue); - if (f != null && f.getDeclaringClass() == HasFields.class - && !Modifier.isFinal(f.getModifiers())) { + if (f != null && f.getDeclaringClass() == HasFields.class && writeAccess) { Object random = randomArg(ftype); f.set(fields, random); expValue = random; @@ -813,7 +818,7 @@ } } } - if (f != null && f.getDeclaringClass() == HasFields.class) { + if (f != null && f.getDeclaringClass() == HasFields.class && writeAccess) { f.set(fields, value); // put it back } if (testNPE) { @@ -862,9 +867,17 @@ public void testSetter(int testMode) throws Throwable { Lookup lookup = PRIVATE; // FIXME: test more lookups than this one - startTest("unreflectSetter"); - for (Object[] c : HasFields.CASES) { - boolean positive = (c[1] != Error.class); + startTest("testSetter"); + for (Object[] c : HasFields.cases(testMode)) { + boolean positive = (c[1] != Error.class) && !(c.length == 3 && c[2] == Error.class); + if ((testMode & TEST_UNREFLECT) != 0 && c.length == 3) { + assertTrue(c[0] instanceof Field && c[2] == Error.class); + Field f = (Field)c[0]; + int mods = f.getModifiers(); + // unreflectSetter should only have write access on instance final field if accessible flag is true + positive = !Modifier.isFinal(mods) || + (!Modifier.isStatic(mods) && f.isAccessible()); + } testSetter(positive, lookup, c[0], c[1], testMode); if (positive) testSetter(positive, lookup, c[0], c[1], testMode | TEST_NPE);