Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8282575

ResourceBundle::getBundle may throw NPE when invoked by JNI code with no caller frame

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Approved
    • Icon: P3 P3
    • 19
    • core-libs
    • 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

            tprinzing Tim Prinzing (Inactive)
            mchung Mandy Chung (Inactive)
            Mandy Chung (Inactive), Naoto Sato
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: