From 09b2f11afb7296ff8756d6dd5df98df75e883e48 Mon Sep 17 00:00:00 2001 From: Brett Meyer Date: Mon, 16 Dec 2013 14:02:23 -0500 Subject: [PATCH] HHH-8655 Classloader conflicts with embedded OSGi frameworks --- .../java/org/hibernate/osgi/OsgiClassLoader.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/hibernate-osgi/src/main/java/org/hibernate/osgi/OsgiClassLoader.java b/hibernate-osgi/src/main/java/org/hibernate/osgi/OsgiClassLoader.java index 90818ba80c..5f0d6a2ff7 100644 --- a/hibernate-osgi/src/main/java/org/hibernate/osgi/OsgiClassLoader.java +++ b/hibernate-osgi/src/main/java/org/hibernate/osgi/OsgiClassLoader.java @@ -51,18 +51,23 @@ public class OsgiClassLoader extends ClassLoader implements Stoppable { private Map> classCache = new HashMap>(); private Map resourceCache = new HashMap(); + + 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... */