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

ClassLoader::registerAsParallelCapable throws NPE if caller is null

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Approved
    • Icon: P3 P3
    • 19
    • core-libs
    • None
    • minimal
    • 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.
    • Java API
    • SE

      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()
            *

            tprinzing Tim Prinzing (Inactive)
            mchung Mandy Chung (Inactive)
            Mandy Chung (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: