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

Support configuring LocalExecutionControl's parent ClassLoader

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Approved
    • Icon: P4 P4
    • 22
    • tools
    • source
    • minimal
    • Low - no existing functionality is changing. Only exposing new APIs.
    • Java API
    • JDK

      Summary

      Augment the API for LocalExecutionControl and LocalExecutionControlProvider to allow for customization of the parent ClassLoader.

      Problem

      JShell defines LocalExecutionControl and LocalExecutionControlProvider classes to support local execution. However, these classes are hard-wired with the system class loader as the parent loader. This means that in non-trivial class loading scenarios, such as when running in web servlet container, the application's classes are not visible to the local execution engine. As a result, it's impossible to resolve any of these classes during local JShell execution.

      The existing code already supports delegation to a parent class loader, so no additional logic is required. All that's needed is a way to configure the parent class loader somehow, e.g., in a custom subclass of LocalExecutionControlProvider.

      The solution chosen here is designed to minimize the number of API changes, while also allowing any such subclasses to inherit a separate bug fix in which LocalExecutionControlProvider currently ignores the --class-path startup flag. See the discussion in pr#15311 for details.

      Solution

      • Add a new constructor to LocalExecutionControl that accepts a parent class loader
      • Add a method createExecutionControl() to LocalExecutionControlProvider that subclasses can override

      Specification

      The new LocalExecutionControl constructor:

      /**
       * Create an instance using the default class loading, but delegating to the specified parent class loader.
       *
       * @param parent parent class loader
       * @since 22
       */
      public LocalExecutionControl(ClassLoader parent) {
          super(new DefaultLoaderDelegate(parent));
      }

      The new method LocalExecutionControlProvider.createExecutionControl():

      /**
       * Create a new {@link ExecutionControl} instance.
       *
       * <p>
       * This method is invoked by {@link #generate generate()}.
       *
       * @param env the {@code ExecutionEnv} for which the {@link ExecutionControl} should be created
       * @param parameters the parameters that were passed to {@link #generate generate()}
       * @return the newly created {@code ExecutionControl}
       * @since 22
       */
      public ExecutionControl createExecutionControl(ExecutionEnv env, Map<String, String> parameters) {
          return new LocalExecutionControl(new DefaultLoaderDelegate());
      }

            acobbs Archie Cobbs
            acobbs Archie Cobbs
            Jan Lahoda
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: