incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r1522872 - /sling/trunk/bundles/commons/classloader/src/main/java/org/apache/sling/commons/classloader/impl/ClassLoaderFacade.java
Date Fri, 13 Sep 2013 11:22:06 GMT
Author: bdelacretaz
Date: Fri Sep 13 11:22:06 2013
New Revision: 1522872

URL: http://svn.apache.org/r1522872
Log:
SLING-3059 - Log stack trace when ClassLoaderFacade detects inactive manager

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=1522872&r1=1522871&r2=1522872&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
Fri Sep 13 11:22:06 2013
@@ -43,6 +43,14 @@ public class ClassLoaderFacade extends C
 
     /** Dynamic class loader manager which manages the dynamic class loader providers for
this facade. */
     private final DynamicClassLoaderManagerImpl manager;
+    
+    /** Used to log stack traces in slf4j for non-critical errors */
+    @SuppressWarnings("serial")
+    static class StackTraceProbe extends Exception {
+        StackTraceProbe(String reason) {
+            super(reason);
+        }
+    }
 
     /**
      * Constructor
@@ -51,12 +59,24 @@ public class ClassLoaderFacade extends C
         this.manager = manager;
     }
 
+    /** Return false if our manager is not active, and log the stack trace
+     *  when that happens, to ease troubleshooting. 
+     */
+    private boolean checkManagerActive() {
+        if(!this.manager.isActive()) {
+            final String msg = "Dynamic class loader has already been deactivated."; 
+            final StackTraceProbe p = new StackTraceProbe(msg);
+            logger.error(msg, p);
+            return false;
+        }
+        return true;
+    }
+
     /**
      * @see java.lang.ClassLoader#getResource(java.lang.String)
      */
     public URL getResource(String name) {
-        if ( !this.manager.isActive() ) {
-            logger.error("Dynamic class loader has already been deactivated.");
+        if (!checkManagerActive()) {
             return null;
         }
         final ClassLoader[] loaders = manager.getDynamicClassLoaders();
@@ -81,8 +101,7 @@ public class ClassLoaderFacade extends C
      * @see java.lang.ClassLoader#getResources(java.lang.String)
      */
     public Enumeration<URL> getResources(String name) throws IOException {
-        if ( !this.manager.isActive() ) {
-            logger.error("Dynamic class loader has already been deactivated.");
+        if(!checkManagerActive()) {
             return Collections.enumeration(EMPTY_LIST);
         }
         final ClassLoader[] loaders = manager.getDynamicClassLoaders();
@@ -107,8 +126,7 @@ public class ClassLoaderFacade extends C
      */
     protected synchronized Class<?> loadClass(String name, boolean resolve)
     throws ClassNotFoundException {
-        if ( !this.manager.isActive() ) {
-            logger.error("Dynamic class loader has already been deactivated.");
+        if(!checkManagerActive()) {
             throw new ClassNotFoundException(name);
         }
         final ClassLoader[] loaders = manager.getDynamicClassLoaders();



Mime
View raw message