< prev index next >
src/java.base/share/classes/java/util/ResourceBundle.java
Print this page
rev 52700 : 8214170: ResourceBundle.Control.newBundle should throw IllegalAccessException when constructor of the resource bundle is not public.
Reviewed-by: rriggs, mchung
@@ -3182,28 +3182,38 @@
if (m.isNamed() && !m.isOpen(bundleClass.getPackageName())) {
throw new IllegalAccessException("unnamed module can't load " +
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.
PrivilegedAction<Void> pa1 = () -> { ctor.setAccessible(true); return null; };
AccessController.doPrivileged(pa1);
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");
if (resourceName == null) {
return bundle;
< prev index next >