-
CSR
-
Resolution: Approved
-
P4
-
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()
toLocalExecutionControlProvider
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());
}
- csr of
-
JDK-8314327 Issues with JShell when using "local" execution engine
-
- Resolved
-