@@ -64,6 +64,13 @@ public abstract class BeanFactoryUtils {
64
64
*/
65
65
private static final Map <String , String > transformedBeanNameCache = new ConcurrentHashMap <>();
66
66
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 );
67
74
68
75
/**
69
76
* Return whether the given name is a factory dereference
@@ -73,7 +80,7 @@ public abstract class BeanFactoryUtils {
73
80
* @see BeanFactory#FACTORY_BEAN_PREFIX
74
81
*/
75
82
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 );
77
84
}
78
85
79
86
/**
@@ -85,14 +92,14 @@ public static boolean isFactoryDereference(@Nullable String name) {
85
92
*/
86
93
public static String transformedBeanName (String name ) {
87
94
Assert .notNull (name , "'name' must not be null" );
88
- if (!name . startsWith ( BeanFactory . FACTORY_BEAN_PREFIX )) {
95
+ if (!isFactoryDereference ( name )) {
89
96
return name ;
90
97
}
91
98
return transformedBeanNameCache .computeIfAbsent (name , beanName -> {
92
99
do {
93
100
beanName = beanName .substring (BeanFactory .FACTORY_BEAN_PREFIX .length ());
94
101
}
95
- while (beanName . startsWith ( BeanFactory . FACTORY_BEAN_PREFIX ));
102
+ while (isFactoryDereference ( beanName ));
96
103
return beanName ;
97
104
});
98
105
}
0 commit comments