X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=common%2Futil%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fyangtools%2Futil%2FClassLoaderUtils.java;fp=common%2Futil%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fyangtools%2Futil%2FClassLoaderUtils.java;h=b5064080ad93757a026209fdabcb17005af71da9;hb=40997323a598045510a525aecd51dd84a5c1c64b;hp=6e65b03658f58b55b3268dd03d9af9fffb49fbc7;hpb=d6b396379c2630b5aaff6b9f6b0596b922223c62;p=yangtools.git diff --git a/common/util/src/main/java/org/opendaylight/yangtools/util/ClassLoaderUtils.java b/common/util/src/main/java/org/opendaylight/yangtools/util/ClassLoaderUtils.java index 6e65b03658..b5064080ad 100644 --- a/common/util/src/main/java/org/opendaylight/yangtools/util/ClassLoaderUtils.java +++ b/common/util/src/main/java/org/opendaylight/yangtools/util/ClassLoaderUtils.java @@ -130,14 +130,28 @@ public final class ClassLoaderUtils { } public static Class loadClassWithTCCL(final String name) throws ClassNotFoundException { - return loadClass(Thread.currentThread().getContextClassLoader(), name); + final Thread thread = Thread.currentThread(); + final ClassLoader tccl = thread.getContextClassLoader(); + if (tccl == null) { + throw new ClassNotFoundException("Thread " + thread + " does not have a Context Class Loader, cannot load " + + name); + } + return loadClass(tccl, name); } - public static Class tryToLoadClassWithTCCL(final String fullyQualifiedName) { + public static Class tryToLoadClassWithTCCL(final String fullyQualifiedClassName) { + final Thread thread = Thread.currentThread(); + final ClassLoader tccl = thread.getContextClassLoader(); + if (tccl == null) { + LOG.debug("Thread {} does not have a Context Class Loader, not loading class {}", thread, + fullyQualifiedClassName); + return null; + } + try { - return loadClassWithTCCL(fullyQualifiedName); + return loadClass(tccl, fullyQualifiedClassName); } catch (final ClassNotFoundException e) { - LOG.debug("Failed to load class {}", fullyQualifiedName, e); + LOG.debug("Failed to load class {}", fullyQualifiedClassName, e); return null; } }