felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rickh...@apache.org
Subject svn commit: r1452999 - /felix/trunk/framework/src/main/java/org/apache/felix/framework/BundleWiringImpl.java
Date Tue, 05 Mar 2013 21:17:02 GMT
Author: rickhall
Date: Tue Mar  5 21:17:02 2013
New Revision: 1452999

URL: http://svn.apache.org/r1452999
Log:
Be more flexible and allow misbehaving threads to continue to issue class load
requests on class loaders from disposed of bundle wirings. Also attempt to
give a reasonable exception when a new class load request is made on a class
loader from a disposed bundle wiring. (FELIX-3907)

Modified:
    felix/trunk/framework/src/main/java/org/apache/felix/framework/BundleWiringImpl.java

Modified: felix/trunk/framework/src/main/java/org/apache/felix/framework/BundleWiringImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/framework/src/main/java/org/apache/felix/framework/BundleWiringImpl.java?rev=1452999&r1=1452998&r2=1452999&view=diff
==============================================================================
--- felix/trunk/framework/src/main/java/org/apache/felix/framework/BundleWiringImpl.java (original)
+++ felix/trunk/framework/src/main/java/org/apache/felix/framework/BundleWiringImpl.java Tue
Mar  5 21:17:02 2013
@@ -641,13 +641,20 @@ public class BundleWiringImpl implements
         return m_revision;
     }
 
-    public synchronized ClassLoader getClassLoader()
+    public ClassLoader getClassLoader()
     {
         if (m_isDisposed)
         {
             return null;
         }
-        if (m_classLoader == null)
+        return getClassLoaderInternal();
+    }
+
+    private synchronized ClassLoader getClassLoaderInternal()
+    {
+        // Only try to create the class loader if the bundle
+        // is not disposed.
+        if (!m_isDisposed && (m_classLoader == null))
         {
             // Determine which class loader to use based on which
             // Java platform we are running on.
@@ -1354,7 +1361,17 @@ public class BundleWiringImpl implements
             throw new ClassNotFoundException(name);
         }
 
-        return getClassLoader().loadClass(name);
+        ClassLoader cl = getClassLoaderInternal();
+        if (cl == null)
+        {
+            throw new ClassNotFoundException(
+                "Unable to load class '"
+                + name
+                + "' because the bundle wiring for "
+                + m_revision.getSymbolicName()
+                + " is no longer valid.");
+        }
+        return cl.loadClass(name);
     }
 
     private boolean isFiltered(String name)
@@ -1469,9 +1486,24 @@ public class BundleWiringImpl implements
                 // If not found, try the revision's own class path.
                 if (result == null)
                 {
-                    result = (isClass)
-                        ? (Object) ((BundleClassLoader) getClassLoader()).findClass(name)
-                        : (Object) m_revision.getResourceLocal(name);
+                    if (isClass)
+                    {
+                        ClassLoader cl = getClassLoaderInternal();
+                        if (cl == null)
+                        {
+                            throw new ClassNotFoundException(
+                                "Unable to load class '"
+                                + name
+                                + "' because the bundle wiring for "
+                                + m_revision.getSymbolicName()
+                                + " is no longer valid.");
+                        }
+                        result = (Object) ((BundleClassLoader) cl).findClass(name);
+                    }
+                    else
+                    {
+                        result = (Object) m_revision.getResourceLocal(name);
+                    }
 
                     // If still not found, then try the revision's dynamic imports.
                     if (result == null)
@@ -1954,6 +1986,21 @@ public class BundleWiringImpl implements
         {
             Class clazz = null;
 
+            // Do a quick check to try to avoid searching for classes on a
+            // disposed class loader, which will avoid some odd exception.
+            // This won't prevent all weird exception, since the wiring could
+            // still get disposed of after this check, but it will prevent
+            // some, perhaps.
+            if (m_wiring.m_isDisposed)
+            {
+                throw new ClassNotFoundException(
+                    "Unable to load class '"
+                    + name
+                    + "' because the bundle wiring for "
+                    + m_wiring.m_revision.getSymbolicName()
+                    + " is no longer valid.");
+            }
+
             // Search for class in bundle revision.
             if (clazz == null)
             {



Mime
View raw message