You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by kk...@apache.org on 2010/02/12 04:19:37 UTC
svn commit: r909212 -
/tomcat/trunk/java/org/apache/catalina/loader/WebappClassLoader.java
Author: kkolinko
Date: Fri Feb 12 03:19:31 2010
New Revision: 909212
URL: http://svn.apache.org/viewvc?rev=909212&view=rev
Log:
When the key is null (i.e., a stale entry), it cannot be removed with an explicit remove(key) call: you'll get an NPE. Those can be removed with expungeStaleEntries() call.
Also, simplified the code: Reference.referent can be accessed by calling get() - no need to use reflection for that.
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=909212&r1=909211&r2=909212&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/loader/WebappClassLoader.java (original)
+++ tomcat/trunk/java/org/apache/catalina/loader/WebappClassLoader.java Fri Feb 12 03:19:31 2010
@@ -2177,15 +2177,13 @@
ThreadLocal.class);
mapRemove.setAccessible(true);
Object[] table = (Object[]) internalTableField.get(map);
+ int staleEntriesCount = 0;
if (table != null) {
for (int j =0; j < table.length; j++) {
if (table[j] != null) {
boolean remove = false;
// Check the key
- Field keyField =
- Reference.class.getDeclaredField("referent");
- keyField.setAccessible(true);
- Object key = keyField.get(table[j]);
+ Object key = ((Reference<?>) table[j]).get();
if (this.equals(key) || (key != null &&
this == key.getClass().getClassLoader())) {
remove = true;
@@ -2200,7 +2198,6 @@
remove = true;
}
if (remove) {
- Object entry = ((Reference<?>) table[j]).get();
Object[] args = new Object[4];
if (key != null) {
args[0] = key.getClass().getCanonicalName();
@@ -2221,11 +2218,21 @@
"webappClassLoader.clearThreadLocal",
args));
}
- mapRemove.invoke(map, entry);
+ if (key == null) {
+ staleEntriesCount++;
+ } else {
+ mapRemove.invoke(map, key);
+ }
}
}
}
}
+ if (staleEntriesCount > 0) {
+ Method mapRemoveStale =
+ map.getClass().getDeclaredMethod("expungeStaleEntries");
+ mapRemoveStale.setAccessible(true);
+ mapRemoveStale.invoke(map);
+ }
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org