From 93c8b7ab04af281a26d05c968fdb0ed03cf0b1c4 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Thu, 6 Mar 2014 22:41:38 +0100 Subject: [PATCH] DefaultListableBeanFactory only puts 'cache-safe' Class keys into its by-type cache Issue: SPR-11520 --- .../factory/support/DefaultListableBeanFactory.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java index 0d1220a90cd..8808eeba691 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -61,6 +61,7 @@ import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.beans.factory.config.DependencyDescriptor; import org.springframework.core.annotation.AnnotationUtils; import org.springframework.util.Assert; +import org.springframework.util.ClassUtils; import org.springframework.util.ObjectUtils; import org.springframework.util.StringUtils; @@ -349,7 +350,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto @Override public String[] getBeanNamesForType(Class type, boolean includeNonSingletons, boolean allowEagerInit) { - if (!isConfigurationFrozen() || type == null || !allowEagerInit) { + if (!isConfigurationFrozen() || type == null || !allowEagerInit) { return doGetBeanNamesForType(type, includeNonSingletons, allowEagerInit); } Map, String[]> cache = @@ -359,7 +360,9 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto return resolvedBeanNames; } resolvedBeanNames = doGetBeanNamesForType(type, includeNonSingletons, allowEagerInit); - cache.put(type, resolvedBeanNames); + if (ClassUtils.isCacheSafe(type, getBeanClassLoader())) { + cache.put(type, resolvedBeanNames); + } return resolvedBeanNames; }