HHH-8655 Classloader conflicts with embedded OSGi frameworks

This commit is contained in:
Brett Meyer 2013-12-16 14:02:23 -05:00
parent 90a08ec3a2
commit 09b2f11afb
1 changed files with 10 additions and 4 deletions

View File

@ -52,17 +52,22 @@ public class OsgiClassLoader extends ClassLoader implements Stoppable {
private Map<String, Class<?>> classCache = new HashMap<String, Class<?>>();
private Map<String, URL> resourceCache = new HashMap<String, URL>();
public OsgiClassLoader() {
// DO NOT use ClassLoader#parent, which is typically the SystemClassLoader for most containers. Instead,
// allow the ClassNotFoundException to be thrown. ClassLoaderServiceImpl will check the SystemClassLoader
// later on. This is especially important for embedded OSGi containers, etc.
super( null );
}
/**
* Load the class and break on first found match. DO NOT use ClassLoader#parent, which is typically the
* SystemClassLoader for most containers. Instead, allow the ClassNotFoundException to be thrown.
* ClassLoaderServiceImpl will check the SystemClassLoader later on.
* Load the class and break on first found match.
*
* TODO: Should this throw a different exception or warn if multiple
* classes were found? Naming collisions can and do happen in OSGi...
*/
@Override
@SuppressWarnings("rawtypes")
protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException {
protected Class<?> findClass(String name) throws ClassNotFoundException {
if ( classCache.containsKey( name ) ) {
return classCache.get( name );
}
@ -96,6 +101,7 @@ public class OsgiClassLoader extends ClassLoader implements Stoppable {
/**
* Load the class and break on first found match.
*
* TODO: Should this throw a different exception or warn if multiple
* classes were found? Naming collisions can and do happen in OSGi...
*/