From 7f895222e17b0970d4f9ab038b2f03c26aaf6f03 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Wed, 11 Dec 2013 11:58:46 +0100 Subject: [PATCH] Revised exclusion of java.lang.Class properties Issue: SPR-11098 (cherry picked from commit 62ea627) --- .../beans/CachedIntrospectionResults.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/spring-beans/src/main/java/org/springframework/beans/CachedIntrospectionResults.java b/spring-beans/src/main/java/org/springframework/beans/CachedIntrospectionResults.java index f83f6acb4e..44d076680d 100644 --- a/spring-beans/src/main/java/org/springframework/beans/CachedIntrospectionResults.java +++ b/spring-beans/src/main/java/org/springframework/beans/CachedIntrospectionResults.java @@ -76,7 +76,7 @@ public class CachedIntrospectionResults { * Needs to be a WeakHashMap with WeakReferences as values to allow * for proper garbage collection in case of multiple class loaders. */ - static final Map classCache = new WeakHashMap(); + static final Map, Object> classCache = new WeakHashMap, Object>(); /** @@ -107,7 +107,7 @@ public class CachedIntrospectionResults { */ public static void clearClassLoader(ClassLoader classLoader) { synchronized (classCache) { - for (Iterator it = classCache.keySet().iterator(); it.hasNext();) { + for (Iterator> it = classCache.keySet().iterator(); it.hasNext();) { Class beanClass = it.next(); if (isUnderneathClassLoader(beanClass.getClassLoader(), classLoader)) { it.remove(); @@ -130,6 +130,7 @@ public class CachedIntrospectionResults { * @return the corresponding CachedIntrospectionResults * @throws BeansException in case of introspection failure */ + @SuppressWarnings("unchecked") static CachedIntrospectionResults forClass(Class beanClass) throws BeansException { CachedIntrospectionResults results; Object value; @@ -137,8 +138,8 @@ public class CachedIntrospectionResults { value = classCache.get(beanClass); } if (value instanceof Reference) { - Reference ref = (Reference) value; - results = (CachedIntrospectionResults) ref.get(); + Reference ref = (Reference) value; + results = ref.get(); } else { results = (CachedIntrospectionResults) value; @@ -260,8 +261,9 @@ public class CachedIntrospectionResults { // This call is slow so we do it once. PropertyDescriptor[] pds = this.beanInfo.getPropertyDescriptors(); for (PropertyDescriptor pd : pds) { - if (Class.class.equals(beanClass) && "classLoader".equals(pd.getName())) { - // Ignore Class.getClassLoader() method - nobody needs to bind to that + if (Class.class.equals(beanClass) && + ("classLoader".equals(pd.getName()) || "protectionDomain".equals(pd.getName()))) { + // Ignore Class.getClassLoader() and getProtectionDomain() methods - nobody needs to bind to those continue; } if (logger.isTraceEnabled()) {