JDK-8282575 : ResourceBundle::getBundle may throw NPE when invoked by JNI code with no caller frame
  • Type: CSR
  • Component: core-libs
  • Sub-Component: java.util:i18n
  • Priority: P3
  • Status: Closed
  • Resolution: Approved
  • Fix Versions: 19
  • Submitted: 2022-03-02
  • Updated: 2022-03-08
  • Resolved: 2022-03-08
Related Reports
CSR :  
Description
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


Comments
Moving to Approved.
08-03-2022