tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r...@apache.org
Subject svn commit: r378251 - /tomcat/container/tc5.5.x/catalina/src/share/org/apache/catalina/loader/WebappClassLoader.java
Date Thu, 16 Feb 2006 14:19:16 GMT
Author: remm
Date: Thu Feb 16 06:19:13 2006
New Revision: 378251

URL: http://svn.apache.org/viewcvs?rev=378251&view=rev
Log:
- Null instances loaded by WCL only.
- Submitted by Matt Jensen.

Modified:
    tomcat/container/tc5.5.x/catalina/src/share/org/apache/catalina/loader/WebappClassLoader.java

Modified: tomcat/container/tc5.5.x/catalina/src/share/org/apache/catalina/loader/WebappClassLoader.java
URL: http://svn.apache.org/viewcvs/tomcat/container/tc5.5.x/catalina/src/share/org/apache/catalina/loader/WebappClassLoader.java?rev=378251&r1=378250&r2=378251&view=diff
==============================================================================
--- tomcat/container/tc5.5.x/catalina/src/share/org/apache/catalina/loader/WebappClassLoader.java
(original)
+++ tomcat/container/tc5.5.x/catalina/src/share/org/apache/catalina/loader/WebappClassLoader.java
Thu Feb 16 06:19:13 2006
@@ -1543,10 +1543,10 @@
                                   > (lastJarAccessed + 90000))) {
                         for (int i = 0; i < jarFiles.length; i++) {
                             try {
-                            	if (jarFiles[i] != null) {
-                            		jarFiles[i].close();
-                            		jarFiles[i] = null;
-                            	}
+                                if (jarFiles[i] != null) {
+                                    jarFiles[i].close();
+                                    jarFiles[i] = null;
+                                }
                             } catch (IOException e) {
                                 if (log.isDebugEnabled()) {
                                     log.debug("Failed to close JAR", e);
@@ -1657,10 +1657,25 @@
                     // Doing something recursively is too risky
                     continue;
                 } else {
-                    field.set(instance, null);
-                    if (log.isDebugEnabled()) {
-                        log.debug("Set field " + field.getName() 
-                                + " to null in class " + instance.getClass().getName());
+                    Object value = field.get(instance);
+                    if (null != value) {
+                        Class valueClass = value.getClass();
+                        if (!loadedByThisOrChild(valueClass)) {
+                            if (log.isDebugEnabled()) {
+                                log.debug("Not setting field " + field.getName() +
+                                        " to null in object of class " + 
+                                        instance.getClass().getName() +
+                                        " because the referenced object was of type " +
+                                        valueClass.getName() + 
+                                        " which was not loaded by this WebappClassLoader.");
+                            }
+                        } else {
+                            field.set(instance, null);
+                            if (log.isDebugEnabled()) {
+                                log.debug("Set field " + field.getName() 
+                                        + " to null in class " + instance.getClass().getName());
+                            }
+                        }
                     }
                 }
             } catch (Throwable t) {
@@ -1672,7 +1687,25 @@
             }
         }
     }
-    
+
+
+    /**
+     * Determine whether a class was loaded by this class loader or one of
+     * its child class loaders.
+     */
+    protected boolean loadedByThisOrChild(Class clazz)
+    {
+        boolean result = false;
+        for (ClassLoader classLoader = clazz.getClassLoader();
+                null != classLoader; classLoader = classLoader.getParent()) {
+            if (classLoader.equals(this)) {
+                result = true;
+                break;
+            }
+        }
+        return result;
+    }    
+
 
     /**
      * Used to periodically signal to the classloader to release JAR resources.
@@ -1682,14 +1715,14 @@
             lastJarAccessed = System.currentTimeMillis();
             if (jarFiles[0] == null) {
                 for (int i = 0; i < jarFiles.length; i++) {
-                	try {
+                    try {
                         jarFiles[i] = new JarFile(jarRealFiles[i]);
-                	} catch (IOException e) {
+                    } catch (IOException e) {
                         if (log.isDebugEnabled()) {
                             log.debug("Failed to open JAR", e);
                         }
                         return false;
-                	}
+                    }
                 }
             }
         }
@@ -1869,6 +1902,7 @@
                 entry.lastModified = attributes.getLastModified();
 
                 if (resource != null) {
+
 
                     try {
                         binaryStream = resource.streamContent();



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Mime
View raw message