Author: remy.maucherat(a)jboss.com
Date: 2009-07-20 12:06:34 -0400 (Mon, 20 Jul 2009)
New Revision: 1138
Modified:
trunk/java/org/apache/catalina/loader/WebappClassLoader.java
trunk/webapps/docs/changelog.xml
Log:
- Port clear reference fix.
Modified: trunk/java/org/apache/catalina/loader/WebappClassLoader.java
===================================================================
--- trunk/java/org/apache/catalina/loader/WebappClassLoader.java 2009-07-17 15:18:55 UTC
(rev 1137)
+++ trunk/java/org/apache/catalina/loader/WebappClassLoader.java 2009-07-20 16:06:34 UTC
(rev 1138)
@@ -267,19 +267,6 @@
protected boolean delegate = false;
- /**
- * Last time a JAR was accessed.
- */
- //protected long lastJarAccessed = 0L;
-
-
- /**
- * The list of local repositories, in the order they should be searched
- * for locally loaded classes or resources.
- */
- //protected String[] repositories = new String[0];
-
-
/**
* Repositories URLs, used to cache the result of getURLs.
*/
@@ -287,55 +274,6 @@
/**
- * Repositories translated as path in the work directory (for Jasper
- * originally), but which is used to generate fake URLs should getURLs be
- * called.
- */
- //protected File[] files = new File[0];
-
-
- /**
- * The list of JARs, in the order they should be searched
- * for locally loaded classes or resources.
- */
- //protected JarFile[] jarFiles = new JarFile[0];
-
-
- /**
- * The list of JARs, in the order they should be searched
- * for locally loaded classes or resources.
- */
- //protected File[] jarRealFiles = new File[0];
-
-
- /**
- * The path which will be monitored for added Jar files.
- */
- //protected String jarPath = null;
-
-
- /**
- * The list of JARs, in the order they should be searched
- * for locally loaded classes or resources.
- */
- //protected String[] jarNames = new String[0];
-
-
- /**
- * The list of JARs last modified dates, in the order they should be
- * searched for locally loaded classes or resources.
- */
- //protected long[] lastModifiedDates = new long[0];
-
-
- /**
- * The list of resources which should be checked when checking for
- * modifications.
- */
- //protected String[] paths = new String[0];
-
-
- /**
* A list of read File and Jndi Permission's required if this loader
* is for a web application context.
*/
@@ -380,11 +318,6 @@
/**
- * Has external repositories.
- */
- //protected boolean hasExternalRepositories = false;
-
- /**
* need conversion for properties files
*/
protected boolean needConvert = false;
@@ -1214,7 +1147,30 @@
// Null out any static or final fields from loaded classes,
// as a workaround for apparent garbage collection bugs
if (ENABLE_CLEAR_REFERENCES) {
- Iterator loadedClasses = resourceEntries.values().iterator();
+ java.util.Collection<ResourceEntry> values = resourceEntries.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 = (ResourceEntry) loadedClasses.next();
if (entry.loadedClass != null) {
Modified: trunk/webapps/docs/changelog.xml
===================================================================
--- trunk/webapps/docs/changelog.xml 2009-07-17 15:18:55 UTC (rev 1137)
+++ trunk/webapps/docs/changelog.xml 2009-07-20 16:06:34 UTC (rev 1138)
@@ -123,6 +123,10 @@
<add>
All other Servlet 3.0 features. (remm)
</add>
+ <fix>
+ <bug>41059</bug>: Reduce one possible source of errors if using
ENABLE_CLEAR_REFERENCES=true.
+ Patch by Curt Arnold. (markt)
+ </fix>
</changelog>
</subsection>
<subsection name="Coyote">
Show replies by date