8214170: ResourceBundle.Control.newBundle should throw IllegalAccessException when constructor of the resource bundle is not public

Reviewed-by: rriggs, mchung
This commit is contained in:
Naoto Sato 2018-11-29 10:13:42 -08:00
parent bddbbd85f9
commit 5fc8ae7c71
4 changed files with 61 additions and 14 deletions

View file

@ -3184,10 +3184,16 @@ public abstract class ResourceBundle {
bundleClass.getName() + " in " + m.toString());
}
try {
// bundle in a unnamed module
Constructor<ResourceBundle> ctor = bundleClass.getConstructor();
Constructor<ResourceBundle> ctor = AccessController.doPrivileged(
new PrivilegedExceptionAction<>() {
@Override
public Constructor<ResourceBundle> run() throws NoSuchMethodException {
return bundleClass.getDeclaredConstructor();
}
});
if (!Modifier.isPublic(ctor.getModifiers())) {
return null;
throw new IllegalAccessException("no-arg constructor in " +
bundleClass.getName() + " is not publicly accessible.");
}
// java.base may not be able to read the bundleClass's module.
@ -3196,12 +3202,16 @@ public abstract class ResourceBundle {
bundle = ctor.newInstance((Object[]) null);
} catch (InvocationTargetException e) {
uncheckedThrow(e);
} catch (PrivilegedActionException e) {
assert e.getException() instanceof NoSuchMethodException;
throw new InstantiationException("public no-arg constructor " +
"does not exist in " + bundleClass.getName());
}
} else {
throw new ClassCastException(c.getName()
+ " cannot be cast to ResourceBundle");
}
} catch (ClassNotFoundException|NoSuchMethodException e) {
} catch (ClassNotFoundException e) {
}
} else if (format.equals("java.properties")) {
final String resourceName = toResourceName0(bundleName, "properties");