Commit 080dd238 authored by Andreas Lauer's avatar Andreas Lauer
Browse files

fix: expect contextClassLoader to be null

Thread.currentThread().getContextClassLoader() may be null
parent 92cd1625
......@@ -27,6 +27,8 @@ import de.dfki.delight.common.ParameterConversionManager;
import de.dfki.delight.di.GuiceUtils;
import de.dfki.delight.transport.MethodCallSender;
import static de.dfki.delight.server.util.ClassLoaderUtil.getContextClassLoader;
/**
* Client part of delight. - allows to connect to some host and to use specific
* apis
......@@ -180,8 +182,7 @@ public class Delight {
public <API> API usingApi(final String handlerName, final Class<API> apiClass, final Class<?>[] parameterTypes,
final Object[] baseCtorArgs) {
return usingApi(handlerName, apiClass, parameterTypes, baseCtorArgs,
Thread.currentThread().getContextClassLoader());
return usingApi(handlerName, apiClass, parameterTypes, baseCtorArgs, getContextClassLoader());
}
public <API> API usingApi(final String handlerName, final Class<API> apiClass, final Class<?>[] parameterTypes,
......
package de.dfki.delight;
import static de.dfki.delight.server.util.ClassLoaderUtil.getContextClassLoader;
import java.io.IOException;
import java.net.URL;
import java.util.Enumeration;
......@@ -30,7 +32,7 @@ public class DelightConfigFinder {
DelightConfigBuilder defaultConfig = null;
Class<? extends ConfigProvider> defaultConfigProviderClass = null;
String defaultLocation = null;
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
ClassLoader classLoader = getContextClassLoader();
try {
Enumeration<URL> resources = classLoader.getResources(DEFAULT_CONFIG_RESOURCE);
if (!resources.hasMoreElements()) {
......
package de.dfki.delight.server.util;
public class ClassLoaderUtil {
/**
* Get the current thread's context ClassLoader. If it is null, the ClassLoader of this class is used.
*/
public static ClassLoader getContextClassLoader() {
ClassLoader cl = Thread.currentThread().getContextClassLoader();
if (cl == null) {
cl = ClassLoaderUtil.class.getClassLoader();
}
return cl;
}
}
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment