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

ClassLoader::registerAsParallelCapable throws NPE if caller is null

    XMLWordPrintable

    Details

    • Type: CSR
    • Status: Closed
    • Priority: P3
    • Resolution: Approved
    • Fix Version/s: 19
    • Component/s: core-libs
    • Labels:
      None
    • Subcomponent:
    • Compatibility Risk:
      minimal
    • Compatibility Risk Description:
      The compatibility risk is minimal. The proposed spec change will throw IllegalCallerException in lieu of NullPointerException or ClassCastException that is thrown by the implementation of the existing releases.
    • Interface Kind:
      Java API
    • Scope:
      SE

      Description

      Summary

      Specify ClassLoader::registerAsParallelCapable to throw IllegalCallerException if invoked with no caller frame or a class that is not a ClassLoader.

      Problem

      The ClassLoader::registerAsParallelCapable method is a caller sensitive method but does not specify what should happen when there are no stack frames to determine the caller or if the caller is not a ClassLoader. A NullPointerException results from the case where there is no caller frame. A ClassCastException results from the case where the caller is not a ClassLoader. These don't provide much diagnostic information.

      Solution

      When there is no caller frame on the stack or the caller class is not a ClassLoader, simply throw an IllegalCallerException to provide better diagnostics.

      Specification

      The spec of java.lang.ClassLoader.registerAsParallelCapable is updated as follows:

       @@ -1606,9 +1606,16 @@ public abstract class ClassLoader {
            * </ol>
            * <p>Note that once a class loader is registered as parallel capable, there
            * is no way to change it back.</p>
      +     * <p>
      +     * In cases where this method is called from a context where the caller is
      +     * not a subclass of {@code ClassLoader} or there is no caller frame on the
      +     * stack (e.g. when called directly from a JNI attached thread),
      +     * {@code IllegalCallerException} is thrown.
      +     * </p>
            *
            * @return  {@code true} if the caller is successfully registered as
            *          parallel capable and {@code false} if otherwise.
      +     * @throws IllegalCallerException if the caller is not a subclass of {@code ClassLoader}
            *
            * @see #isRegisteredAsParallelCapable()
            *

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              tprinzing Tim Prinzing
              Reporter:
              mchung Mandy Chung
              Reviewed By:
              Mandy Chung
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: