incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r883727 - /sling/trunk/bundles/commons/classloader/src/main/java/org/apache/sling/commons/classloader/impl/ClassLoaderFacade.java
Date Tue, 24 Nov 2009 15:23:06 GMT
Author: cziegeler
Date: Tue Nov 24 15:23:05 2009
New Revision: 883727

URL: http://svn.apache.org/viewvc?rev=883727&view=rev
Log:
SLING-1201 : ClassLoaderFacade should not throw runtime exceptions and handle getResources()
correctly

Modified:
    sling/trunk/bundles/commons/classloader/src/main/java/org/apache/sling/commons/classloader/impl/ClassLoaderFacade.java

Modified: sling/trunk/bundles/commons/classloader/src/main/java/org/apache/sling/commons/classloader/impl/ClassLoaderFacade.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/commons/classloader/src/main/java/org/apache/sling/commons/classloader/impl/ClassLoaderFacade.java?rev=883727&r1=883726&r2=883727&view=diff
==============================================================================
--- sling/trunk/bundles/commons/classloader/src/main/java/org/apache/sling/commons/classloader/impl/ClassLoaderFacade.java
(original)
+++ sling/trunk/bundles/commons/classloader/src/main/java/org/apache/sling/commons/classloader/impl/ClassLoaderFacade.java
Tue Nov 24 15:23:05 2009
@@ -20,12 +20,14 @@
 
 import java.io.IOException;
 import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collections;
 import java.util.Enumeration;
+import java.util.List;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-
 /**
  * The <code>ClassLoaderFacade</code> is a facade
  * for the dynamic class loading.
@@ -54,7 +56,8 @@
      */
     public URL getResource(String name) {
         if ( !this.manager.isActive() ) {
-            throw new RuntimeException("Dynamic class loader has already been deactivated.");
+            logger.error("Dynamic class loader has already been deactivated.");
+            return null;
         }
         final ClassLoader[] loaders = manager.getDynamicClassLoaders();
         for(final ClassLoader cl : loaders) {
@@ -72,35 +75,41 @@
         return null;
     }
 
+    private final List<URL> EMPTY_LIST = Collections.emptyList();
+
     /**
      * @see java.lang.ClassLoader#getResources(java.lang.String)
      */
     public Enumeration<URL> getResources(String name) throws IOException {
         if ( !this.manager.isActive() ) {
-            throw new RuntimeException("Dynamic class loader has already been deactivated.");
+            logger.error("Dynamic class loader has already been deactivated.");
+            return Collections.enumeration(EMPTY_LIST);
         }
         final ClassLoader[] loaders = manager.getDynamicClassLoaders();
+        final List<URL> resources = new ArrayList<URL>();
         for(final ClassLoader cl : loaders) {
             if ( cl != null ) {
                 try {
                     final Enumeration<URL> e = cl.getResources(name);
                     if ( e != null && e.hasMoreElements() ) {
-                        return e;
+                        resources.addAll(Collections.list(e));
                     }
                 } catch (Throwable t) {
                     logger.error("Exception while querying class loader " + cl + " for resources
" + name, t);
                 }
             }
         }
-        return null;
+        return Collections.enumeration(resources);
     }
 
-    @Override
+    /**
+     * @see java.lang.ClassLoader#loadClass(java.lang.String, boolean)
+     */
     protected synchronized Class<?> loadClass(String name, boolean resolve)
     throws ClassNotFoundException {
-
         if ( !this.manager.isActive() ) {
-            throw new RuntimeException("Dynamic class loader has already been deactivated.");
+            logger.error("Dynamic class loader has already been deactivated.");
+            throw new ClassNotFoundException("Class not found: " + name);
         }
         final ClassLoader[] loaders = manager.getDynamicClassLoaders();
         for(final ClassLoader cl : loaders) {



Mime
View raw message