Skip to content
Closed
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
19 changes: 18 additions & 1 deletion src/main/java/org/scijava/plugin/DefaultPluginFinder.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,24 @@ private PluginInfo<SciJavaPlugin> createInfo(

private ClassLoader getClassLoader() {
if (customClassLoader != null) return customClassLoader;
return Thread.currentThread().getContextClassLoader();

/*
* If not even the current class can be found by the current
* Thread's context class loader, chances are that the plugins
* the caller tries to discover using this plugin finder cannot
* be found, either. Therefore let's use the current class'
* class loader in that case. This is not completely
* fool-proof, but better than nothing.
*/
final ClassLoader thisLoader = getClass().getClassLoader();
final ClassLoader contextLoader =
Thread.currentThread().getContextClassLoader();
for (ClassLoader loader = contextLoader;
loader != null;
loader = loader.getParent()) {
if (thisLoader == loader) return contextLoader;
}
return thisLoader;
}

}