Skip to content

Commit 5216a8d

Browse files
committed
*Always* use the context class loader
If we ever limit which class loader we use as parent or to discover the available dependencies by using the class loader that happened to load MiniMaven, we will be in for a *lot* of trouble in the future, e.g. with ImageJ 1.x' PluginClassLoader. So let's not do that. Let's use the current thread's context class loader, like everywhere else we need a class loader. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent d7f00fc commit 5216a8d

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/main/java/org/scijava/plugins/scripting/java/JavaEngine.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ public Object eval(Reader reader) throws ScriptException {
168168
urls[i] = new URL("file:" + paths[i]
169169
+ (paths[i].endsWith(".jar") ? "" : "/"));
170170
URLClassLoader classLoader = new URLClassLoader(urls,
171-
getClass().getClassLoader());
171+
Thread.currentThread().getContextClassLoader());
172172

173173
// needed for sezpoz
174174
Thread.currentThread().setContextClassLoader(classLoader);
@@ -608,7 +608,8 @@ private static Element append(final Document document, final Element parent, fin
608608
*/
609609
private static List<Coordinate> getAllDependencies(final BuildEnvironment env) {
610610
final List<Coordinate> result = new ArrayList<Coordinate>();
611-
for (ClassLoader loader = env.getClass().getClassLoader(); loader != null; loader = loader.getParent()) {
611+
for (ClassLoader loader = Thread.currentThread().getContextClassLoader();
612+
loader != null; loader = loader.getParent()) {
612613
if (loader instanceof URLClassLoader) {
613614
for (final URL url : ((URLClassLoader)loader).getURLs()) {
614615
if (url.getProtocol().equals("file")) {

0 commit comments

Comments
 (0)