View | Details | Raw Unified | Return to bug 48837
Collapse All | Expand All

(-)java/org/apache/catalina/loader/WebappClassLoader.java (-8 / +34 lines)
Lines 111-116 Link Here
111
 * @author Craig R. McClanahan
111
 * @author Craig R. McClanahan
112
 * @version $Revision$ $Date$
112
 * @version $Revision$ $Date$
113
 */
113
 */
114
/**
115
 * @author slaurent
116
 *
117
 */
114
public class WebappClassLoader
118
public class WebappClassLoader
115
    extends URLClassLoader
119
    extends URLClassLoader
116
    implements Reloader, Lifecycle
120
    implements Reloader, Lifecycle
Lines 249-255 Link Here
249
253
250
254
251
    /**
255
    /**
252
     * Construct a new ClassLoader with no defined repositories and no
256
     * Construct a new ClassLoader with no defined repositories but a
253
     * parent ClassLoader.
257
     * parent ClassLoader.
254
     */
258
     */
255
    public WebappClassLoader(ClassLoader parent) {
259
    public WebappClassLoader(ClassLoader parent) {
Lines 1970-1976 Link Here
1970
        for (Thread thread : threads) {
1974
        for (Thread thread : threads) {
1971
            if (thread != null) {
1975
            if (thread != null) {
1972
                ClassLoader ccl = thread.getContextClassLoader();
1976
                ClassLoader ccl = thread.getContextClassLoader();
1973
                if (ccl != null && ccl == this) {
1977
                if (ccl == this) {
1974
                    // Don't warn about this thread
1978
                    // Don't warn about this thread
1975
                    if (thread == Thread.currentThread()) {
1979
                    if (thread == Thread.currentThread()) {
1976
                        continue;
1980
                        continue;
Lines 2169-2176 Link Here
2169
                        boolean remove = false;
2173
                        boolean remove = false;
2170
                        // Check the key
2174
                        // Check the key
2171
                        Object key = ((Reference<?>) table[j]).get();
2175
                        Object key = ((Reference<?>) table[j]).get();
2172
                        if (this.equals(key) || (key != null &&
2176
                        if (this.equals(key) || isLoadedByThisWebAppClassLoader(key)) {
2173
                                this == key.getClass().getClassLoader())) {
2174
                            remove = true;
2177
                            remove = true;
2175
                        }
2178
                        }
2176
                        // Check the value
2179
                        // Check the value
Lines 2178-2195 Link Here
2178
                            table[j].getClass().getDeclaredField("value");
2181
                            table[j].getClass().getDeclaredField("value");
2179
                        valueField.setAccessible(true);
2182
                        valueField.setAccessible(true);
2180
                        Object value = valueField.get(table[j]);
2183
                        Object value = valueField.get(table[j]);
2181
                        if (this.equals(value) || (value != null &&
2184
                        if (this.equals(value) || isLoadedByThisWebAppClassLoader(value)) {
2182
                                this == value.getClass().getClassLoader())) {
2183
                            remove = true;
2185
                            remove = true;
2184
                        }
2186
                        }
2185
                        if (remove) {
2187
                        if (remove) {
2186
                            Object[] args = new Object[4];
2188
                            Object[] args = new Object[4];
2187
                            if (key != null) {
2189
                            if (key != null) {
2188
                                args[0] = key.getClass().getCanonicalName();
2190
                                args[0] = getPrettyClassName(key.getClass());
2189
                                args[1] = key.toString();
2191
                                args[1] = key.toString();
2190
                            }
2192
                            }
2191
                            if (value != null) {
2193
                            if (value != null) {
2192
                                args[2] = value.getClass().getCanonicalName();
2194
                                args[2] = getPrettyClassName(value.getClass());
2193
                                args[3] = value.toString();
2195
                                args[3] = value.toString();
2194
                            }
2196
                            }
2195
                            if (value == null) {
2197
                            if (value == null) {
Lines 2220-2225 Link Here
2220
            }
2222
            }
2221
        }
2223
        }
2222
    }
2224
    }
2225
    
2226
    private String getPrettyClassName(Class clazz) {
2227
    	String name = clazz.getCanonicalName();
2228
    	if(name==null){
2229
    		name = clazz.getName();
2230
    	}
2231
    	return name;
2232
    }
2233
    
2234
    /**
2235
     * @param o object to test
2236
     * @return true if o has been loaded by the current classloader or one of its descendants.
2237
     */
2238
    private boolean isLoadedByThisWebAppClassLoader(Object o) {
2239
    	if(o == null) {
2240
    		return false;
2241
    	}
2242
    	for(ClassLoader loader = o.getClass().getClassLoader(); loader != null; loader = loader.getParent()) {
2243
    		if(loader == this) {
2244
    			return true;
2245
    		}
2246
    	}
2247
    	return false;
2248
    }
2223
2249
2224
    /*
2250
    /*
2225
     * Get the set of current threads as an array.
2251
     * Get the set of current threads as an array.

Return to bug 48837