Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MSHARED-1359] Use child first classloader in BeanShellScriptInterpreter #114

Merged
merged 1 commit into from
Mar 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,50 @@
*/
class BeanShellScriptInterpreter implements ScriptInterpreter {

private static class AppendableURLClassLoader extends URLClassLoader {
AppendableURLClassLoader() {
private static class ChildFirstURLClassLoader extends URLClassLoader {
ChildFirstURLClassLoader() {
super(new URL[] {}, Thread.currentThread().getContextClassLoader());
}

@Override
public void addURL(URL url) {
super.addURL(url);
}

@Override
protected synchronized Class<?> loadClass(final String name, final boolean resolve)
throws ClassNotFoundException {

Class<?> c = findLoadedClass(name);
if (c != null) {
return c;
}

try {
c = super.findClass(name);
} catch (ClassNotFoundException e) {
// ignore
}

if (c == null) {
c = super.loadClass(name, resolve);
}

if (resolve) {
resolveClass(c);
}

return c;
}

@Override
public URL getResource(final String name) {
URL url = findResource(name);
return url != null ? url : super.getResource(name);
}
}

private final AppendableURLClassLoader classLoader = new AppendableURLClassLoader();
private final ChildFirstURLClassLoader classLoader = new ChildFirstURLClassLoader();

@Override
public void setClassPath(List<String> classPath) {
Expand Down