Skip to content

Commit

Permalink
[MSHARED-1359] Use child first classloader in BeanShellScriptInterpreter
Browse files Browse the repository at this point in the history
  • Loading branch information
slawekjaranowski committed Mar 30, 2024
1 parent 9dfe91d commit 91b11c3
Showing 1 changed file with 35 additions and 3 deletions.
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

0 comments on commit 91b11c3

Please sign in to comment.