CachedIntrospectionResults - Not strongly caching class because it is not cache-safe

Viewed 1299

Does anyone know what does this warning mean?

o.s.b.CachedIntrospectionResults - Not strongly caching class because it is not cache-safe

It is a warning logged in my play framework application. It seems has something to do with this class from spring but I can't find more info...

1 Answers

It seems that the message is thrown from the org.springframework.beans.CachedIntrospectionResults#forClass method of the spring-beans library which uses the org.springframework.util.ClassUtils#isCacheSafe method of the spring-core library for checking whether the specified class is cache-safe (it checks whether the class is loaded by the same class loader as the CachedIntrospectionResults class).

CachedIntrospectionResults#forClass:

/**
* Create CachedIntrospectionResults for the given bean class.
* @param beanClass the bean class to analyze
* @return the corresponding CachedIntrospectionResults
* @throws BeansException in case of introspection failure
*/
static CachedIntrospectionResults forClass(Class<?> beanClass) {
    ...
    if (ClassUtils.isCacheSafe(...)) {
        ...
    }
    else {
        ...
        logger.debug("Not strongly caching class [" + beanClass.getName() + "] because it is not cache-safe");
    }
    ...
}

ClassUtils#isCacheSafe:

/**
* Check whether the given class is cache-safe in the given context,
* i.e. whether it is loaded by the given ClassLoader or a parent of it.
* @param clazz the class to analyze
* @param classLoader the ClassLoader to potentially cache metadata in
* (may be {@code null} which indicates the system class loader)
*/
public static boolean isCacheSafe(Class<?> clazz, @Nullable ClassLoader classLoader) {
...

Maybe the sources of CachedIntrospectionResults and ClassUtils classes will clarify the problem.

Related