Top Description Fields Constructors Methods
org.springframework.beans

public final Class CachedIntrospectionResults

extends Object
Class Inheritance
Imports
java.beans.BeanInfo, .IntrospectionException, .PropertyDescriptor, java.lang.reflect.Method, .Modifier, java.net.URL, java.security.ProtectionDomain, java.util.Collections, .HashSet, .LinkedHashMap, .List, .Map, .Set, java.util.concurrent.ConcurrentHashMap, .ConcurrentMap, org.apache.commons.logging.Log, .LogFactory, org.springframework.core.io.support.SpringFactoriesLoader, org.springframework.lang.Nullable, org.springframework.util.ClassUtils, .ConcurrentReferenceHashMap, .StringUtils

Internal class that caches JavaBeans java.beans.PropertyDescriptor information for a Java class. Not intended for direct use by application code.

Necessary for Spring's own caching of bean descriptors within the application ClassLoader, rather than relying on the JDK's system-wide BeanInfo cache (in order to avoid leaks on individual application shutdown in a shared JVM).

Information is cached statically, so we don't need to create new objects of this class for every JavaBean we manipulate. Hence, this class implements the factory design pattern, using a private constructor and a static forClass(Class) factory method to obtain instances.

Note that for caching to work effectively, some preconditions need to be met: Prefer an arrangement where the Spring jars live in the same ClassLoader as the application classes, which allows for clean caching along with the application's lifecycle in any case.

As of 6.0, Spring's default introspection discovers basic JavaBeans properties through an efficient method reflection pass. For full JavaBeans introspection including indexed properties and all JDK-supported customizers, configure a META-INF/spring.factories file with the following content: org.springframework.beans.BeanInfoFactory=org.springframework.beans.StandardBeanInfoFactory For Spring 5.3 compatible extended introspection including non-void setter methods: org.springframework.beans.BeanInfoFactory=org.springframework.beans.ExtendedBeanInfoFactory

Authors
Rod Johnson, Juergen Hoeller
Since
05 May 2001
See Also
acceptClassLoader(ClassLoader), clearClassLoader(ClassLoader), forClass(Class)

Field Summary

Modifier and TypeField and Description
pack-priv static final Set<ClassLoader>
acceptedClassLoaders

Set of ClassLoaders that this CachedIntrospectionResults class will always accept classes from, even if the classes do not qualify as cache-safe.

private final BeanInfo
beanInfo

The BeanInfo object for the introspected bean class.

private static final List<BeanInfoFactory>
private static final Log
private final Map<String, PropertyDescriptor>
propertyDescriptors

PropertyDescriptor objects keyed by property name String.

private static final SimpleBeanInfoFactory
pack-priv static final ConcurrentMap<Class<?>, CachedIntrospectionResults>
softClassCache

Map keyed by Class containing CachedIntrospectionResults, softly held.

pack-priv static final ConcurrentMap<Class<?>, CachedIntrospectionResults>
strongClassCache

Map keyed by Class containing CachedIntrospectionResults, strongly held.

Constructor Summary

AccessConstructor and Description
private
CachedIntrospectionResults(Class<?>
the bean class to analyze
beanClass
)

Create a new CachedIntrospectionResults instance for the given class.

Method Summary

Modifier and TypeMethod and Description
public static void
acceptClassLoader(ClassLoader
the ClassLoader to accept
classLoader
)

Accept the given ClassLoader as cache-safe, even if its classes would not qualify as cache-safe in this CachedIntrospectionResults class.

private PropertyDescriptor
public static void
clearClassLoader(ClassLoader
the ClassLoader to clear the cache for
classLoader
)

Clear the introspection cache for the given ClassLoader, removing the introspection results for all classes underneath that ClassLoader, and removing the ClassLoader (and its children) from the acceptance list.

pack-priv static CachedIntrospectionResults

Returns:

the corresponding CachedIntrospectionResults
forClass
(Class<?>
the bean class to analyze
beanClass
)

Create CachedIntrospectionResults for the given bean class.

pack-priv Class<?>
private static BeanInfo

Returns:

the resulting BeanInfo descriptor (never null)
getBeanInfo
(Class<?>
the target class to introspect
beanClass
)

Retrieve a BeanInfo descriptor for the given target class.

pack-priv BeanInfo
pack-priv PropertyDescriptor
pack-priv PropertyDescriptor[]
private void
introspectInterfaces(Class<?> beanClass, Class<?> currClass, Set<String> readMethodNames)

private void
introspectPlainAccessors(Class<?> beanClass, Set<String> readMethodNames)

private static boolean

Returns:

whether the given ClassLoader is accepted
isClassLoaderAccepted
(ClassLoader
the ClassLoader to check
classLoader
)

Check whether this CachedIntrospectionResults class is configured to accept the given ClassLoader.

private boolean
isInvalidReadOnlyPropertyType(Class<?> returnType, Class<?> beanClass)

private boolean
private static boolean
isUnderneathClassLoader(ClassLoader
the candidate ClassLoader to check
candidate
,
ClassLoader
the parent ClassLoader to check for
parent
)

Check whether the given ClassLoader is underneath the given parent, that is, whether the parent is within the candidate's hierarchy.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

acceptedClassLoadersback to summary
pack-priv static final Set<ClassLoader> acceptedClassLoaders

Set of ClassLoaders that this CachedIntrospectionResults class will always accept classes from, even if the classes do not qualify as cache-safe.

beanInfoback to summary
private final BeanInfo beanInfo

The BeanInfo object for the introspected bean class.

beanInfoFactoriesback to summary
private static final List<BeanInfoFactory> beanInfoFactories
loggerback to summary
private static final Log logger
propertyDescriptorsback to summary
private final Map<String, PropertyDescriptor> propertyDescriptors

PropertyDescriptor objects keyed by property name String.

simpleBeanInfoFactoryback to summary
private static final SimpleBeanInfoFactory simpleBeanInfoFactory
softClassCacheback to summary
pack-priv static final ConcurrentMap<Class<?>, CachedIntrospectionResults> softClassCache

Map keyed by Class containing CachedIntrospectionResults, softly held. This variant is being used for non-cache-safe bean classes.

strongClassCacheback to summary
pack-priv static final ConcurrentMap<Class<?>, CachedIntrospectionResults> strongClassCache

Map keyed by Class containing CachedIntrospectionResults, strongly held. This variant is being used for cache-safe bean classes.

Constructor Detail

CachedIntrospectionResultsback to summary
private CachedIntrospectionResults(Class<?> beanClass) throws BeansException

Create a new CachedIntrospectionResults instance for the given class.

Parameters
beanClass:Class<?>

the bean class to analyze

Exceptions
BeansException:
in case of introspection failure

Method Detail

acceptClassLoaderback to summary
public static void acceptClassLoader(ClassLoader classLoader)

Accept the given ClassLoader as cache-safe, even if its classes would not qualify as cache-safe in this CachedIntrospectionResults class.

This configuration method is only relevant in scenarios where the Spring classes reside in a 'common' ClassLoader (e.g. the system ClassLoader) whose lifecycle is not coupled to the application. In such a scenario, CachedIntrospectionResults would by default not cache any of the application's classes, since they would create a leak in the common ClassLoader.

Any acceptClassLoader call at application startup should be paired with a clearClassLoader call at application shutdown.

Parameters
classLoader:ClassLoader

the ClassLoader to accept

buildGenericTypeAwarePropertyDescriptorback to summary
private PropertyDescriptor buildGenericTypeAwarePropertyDescriptor(Class<?> beanClass, PropertyDescriptor pd)
clearClassLoaderback to summary
public static void clearClassLoader(ClassLoader classLoader)

Clear the introspection cache for the given ClassLoader, removing the introspection results for all classes underneath that ClassLoader, and removing the ClassLoader (and its children) from the acceptance list.

Parameters
classLoader:ClassLoader

the ClassLoader to clear the cache for

forClassback to summary
pack-priv static CachedIntrospectionResults forClass(Class<?> beanClass) throws BeansException

Create CachedIntrospectionResults for the given bean class.

Parameters
beanClass:Class<?>

the bean class to analyze

Returns:CachedIntrospectionResults

the corresponding CachedIntrospectionResults

Exceptions
BeansException:
in case of introspection failure
getBeanClassback to summary
pack-priv Class<?> getBeanClass()
getBeanInfoback to summary
private static BeanInfo getBeanInfo(Class<?> beanClass) throws IntrospectionException

Retrieve a BeanInfo descriptor for the given target class.

Parameters
beanClass:Class<?>

the target class to introspect

Returns:BeanInfo

the resulting BeanInfo descriptor (never null)

Exceptions
IntrospectionException:
from introspecting the given bean class
getBeanInfoback to summary
pack-priv BeanInfo getBeanInfo()
getPropertyDescriptorback to summary
pack-priv PropertyDescriptor getPropertyDescriptor(String name)
Annotations
@Nullable
getPropertyDescriptorsback to summary
pack-priv PropertyDescriptor[] getPropertyDescriptors()
introspectInterfacesback to summary
private void introspectInterfaces(Class<?> beanClass, Class<?> currClass, Set<String> readMethodNames) throws IntrospectionException
introspectPlainAccessorsback to summary
private void introspectPlainAccessors(Class<?> beanClass, Set<String> readMethodNames) throws IntrospectionException
isClassLoaderAcceptedback to summary
private static boolean isClassLoaderAccepted(ClassLoader classLoader)

Check whether this CachedIntrospectionResults class is configured to accept the given ClassLoader.

Parameters
classLoader:ClassLoader

the ClassLoader to check

Returns:boolean

whether the given ClassLoader is accepted

See Also
acceptClassLoader
isInvalidReadOnlyPropertyTypeback to summary
private boolean isInvalidReadOnlyPropertyType(Class<?> returnType, Class<?> beanClass)
isPlainAccessorback to summary
private boolean isPlainAccessor(Method method)
isUnderneathClassLoaderback to summary
private static boolean isUnderneathClassLoader(ClassLoader candidate, ClassLoader parent)

Check whether the given ClassLoader is underneath the given parent, that is, whether the parent is within the candidate's hierarchy.

Parameters
candidate:ClassLoader

the candidate ClassLoader to check

parent:ClassLoader

the parent ClassLoader to check for