8210496: Improve filtering for classes with security sensitive fields

Reviewed-by: plevart, mchung
This commit is contained in:
Alan Bateman 2018-09-19 08:49:07 +01:00
parent a17816f881
commit 9c70e26c14
8 changed files with 138 additions and 66 deletions

View file

@ -113,25 +113,17 @@ public class AccessTest {
if (!Modifier.isFinal(f.getModifiers())) {
throw new RuntimeException("not a final field");
}
makeFinalNonFinal(f);
}
public Void call() throws Exception {
Members obj = isStatic ? null : new Members();
try {
f.set(obj, 20);
checkValue(obj, 20);
throw new RuntimeException("IllegalAccessException expected");
} catch (IllegalAccessException e) {
throw e;
// expected
}
return null;
}
void checkValue(Object obj, int expected) throws Exception {
int value = (int) f.get(obj);
if (value != expected) {
throw new RuntimeException("unexpectd value: " + value);
}
}
}
public static class PublicFinalField extends FinalField {
@ -157,15 +149,4 @@ public class AccessTest {
super("privateStaticFinalField");
}
}
private static void makeFinalNonFinal(Field f) throws ReflectiveOperationException {
Field modifiers = Field.class.getDeclaredField("modifiers");
modifiers.setAccessible(true);
modifiers.set(f, modifiers.getInt(f) & ~Modifier.FINAL);
f.setAccessible(true);
if (Modifier.isFinal(f.getModifiers())) {
throw new RuntimeException("should be a non-final field");
}
}
}