-
CSR
-
Resolution: Approved
-
P3
-
None
-
behavioral
-
minimal
-
The code functions the same as before when there is a caller. When there is no caller information a reasonable default behavior is provided instead of throwing NPE.
-
Java API
-
SE
Summary
Specify ResourceBundle::getBundle methods and ResourceBundle::clearCache to use the unnamed module of the system class loader when no caller is available.
Problem
The various overloads of ResourceBundle::getBundle are caller sensitive but do not specify what should happen where there are no stack frames to determine the caller. Currently a NullPointerException results from the case where there is no caller frame, which prevents loading resources when called directly from a JNI attached thread. The method ResourceBundle::clearCache also has this problem.
Solution
In all places where the caller class was used directly to get a Module, a static method is called to translate the caller to a Module. If there is a caller it returns caller.getModule() as it previously did, but if null returns ClassLoader.getSystemClassLoader().getUnnamedModule() instead of throwing a NPE.
Specification
The following change to the class specification:
@@ -256,6 +256,12 @@ import static sun.security.util.SecurityConstants.GET_CLASSLOADER_PERMISSION;
* resource bundle provider</a>, it does not fall back to the
* class loader search.
*
+ * <p>
+ * In cases where the {@code getBundle} factory method is called from a context
+ * where there is no caller frame on the stack (e.g. when called directly from
+ * a JNI attached thread), the caller module is default to the unnamed module for the
+ * {@linkplain ClassLoader#getSystemClassLoader system class loader}.
+ *
* <h3>Resource bundles in automatic modules</h3>
*
* A common format of resource bundles is in {@linkplain PropertyResourceBundle
- csr of
-
JDK-8280902 ResourceBundle::getBundle may throw NPE when invoked by JNI code with no caller frame
- Resolved