@@ -64,6 +64,13 @@ public abstract class BeanFactoryUtils {
6464 */
6565 private static final Map <String , String > transformedBeanNameCache = new ConcurrentHashMap <>();
6666
67+ /**
68+ * Used to dereference a {@link FactoryBean} instance and distinguish it from
69+ * beans <i>created</i> by the FactoryBean. For example, if the bean named
70+ * {@code myJndiObject} is a FactoryBean, getting {@code &myJndiObject}
71+ * will return the factory, not the instance returned by the factory.
72+ */
73+ private static final char FACTORY_BEAN_PREFIX = BeanFactory .FACTORY_BEAN_PREFIX .charAt (0 );
6774
6875 /**
6976 * Return whether the given name is a factory dereference
@@ -73,7 +80,7 @@ public abstract class BeanFactoryUtils {
7380 * @see BeanFactory#FACTORY_BEAN_PREFIX
7481 */
7582 public static boolean isFactoryDereference (@ Nullable String name ) {
76- return (name != null && name .startsWith ( BeanFactory . FACTORY_BEAN_PREFIX ) );
83+ return (name != null && ! name .isEmpty () && name . charAt ( 0 ) == FACTORY_BEAN_PREFIX );
7784 }
7885
7986 /**
@@ -85,14 +92,14 @@ public static boolean isFactoryDereference(@Nullable String name) {
8592 */
8693 public static String transformedBeanName (String name ) {
8794 Assert .notNull (name , "'name' must not be null" );
88- if (!name . startsWith ( BeanFactory . FACTORY_BEAN_PREFIX )) {
95+ if (!isFactoryDereference ( name )) {
8996 return name ;
9097 }
9198 return transformedBeanNameCache .computeIfAbsent (name , beanName -> {
9299 do {
93100 beanName = beanName .substring (BeanFactory .FACTORY_BEAN_PREFIX .length ());
94101 }
95- while (beanName . startsWith ( BeanFactory . FACTORY_BEAN_PREFIX ));
102+ while (isFactoryDereference ( beanName ));
96103 return beanName ;
97104 });
98105 }
0 commit comments