tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r795152 - /tomcat/trunk/java/org/apache/catalina/loader/WebappClassLoader.java
Date Fri, 17 Jul 2009 17:19:59 GMT
Author: markt
Date: Fri Jul 17 17:19:59 2009
New Revision: 795152

URL: http://svn.apache.org/viewvc?rev=795152&view=rev
Log:
Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=41059
Reduce one possible source of errors if using ENABLE_CLEAR_REFERENCES=true

Modified:
    tomcat/trunk/java/org/apache/catalina/loader/WebappClassLoader.java

Modified: tomcat/trunk/java/org/apache/catalina/loader/WebappClassLoader.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/loader/WebappClassLoader.java?rev=795152&r1=795151&r2=795152&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/loader/WebappClassLoader.java (original)
+++ tomcat/trunk/java/org/apache/catalina/loader/WebappClassLoader.java Fri Jul 17 17:19:59
2009
@@ -1653,7 +1653,31 @@
         // Null out any static or final fields from loaded classes,
         // as a workaround for apparent garbage collection bugs
         if (ENABLE_CLEAR_REFERENCES) {
-            Iterator<ResourceEntry> loadedClasses = ((HashMap<String, ResourceEntry>)
resourceEntries.clone()).values().iterator();
+            java.util.Collection<ResourceEntry> values =
+                ((HashMap<String,ResourceEntry>) resourceEntries.clone()).values();
+            Iterator<ResourceEntry> loadedClasses = values.iterator();
+            //
+            // walk through all loaded class to trigger initialization for
+            //    any uninitialized classes, otherwise initialization of
+            //    one class may call a previously cleared class.
+            while(loadedClasses.hasNext()) {
+                ResourceEntry entry = loadedClasses.next();
+                if (entry.loadedClass != null) {
+                    Class<?> clazz = entry.loadedClass;
+                    try {
+                        Field[] fields = clazz.getDeclaredFields();
+                        for (int i = 0; i < fields.length; i++) {
+                            if(Modifier.isStatic(fields[i].getModifiers())) {
+                                fields[i].get(null);
+                                break;
+                            }
+                        }
+                    } catch(Throwable t) {
+                        // Ignore
+                    }
+                }
+            }
+            loadedClasses = values.iterator();
             while (loadedClasses.hasNext()) {
                 ResourceEntry entry = loadedClasses.next();
                 if (entry.loadedClass != null) {



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


Mime
View raw message