Skip to content

Commit f79baec

Browse files
committed
Polishing
(cherry picked from commit 46fc7fb)
1 parent d1c0ea7 commit f79baec

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractAutowireCapableBeanFactory.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -774,11 +774,12 @@ protected Class<?> getTypeForFactoryMethod(String beanName, RootBeanDefinition m
774774
@Override
775775
protected Class<?> getTypeForFactoryBean(String beanName, RootBeanDefinition mbd) {
776776
String factoryBeanName = mbd.getFactoryBeanName();
777-
final String factoryMethodName = mbd.getFactoryMethodName();
777+
String factoryMethodName = mbd.getFactoryMethodName();
778778

779779
if (factoryBeanName != null) {
780780
if (factoryMethodName != null) {
781-
// Try to obtain the FactoryBean's object type without instantiating it at all.
781+
// Try to obtain the FactoryBean's object type from its factory method declaration
782+
// without instantiating the containing bean at all.
782783
BeanDefinition fbDef = getBeanDefinition(factoryBeanName);
783784
if (fbDef instanceof AbstractBeanDefinition) {
784785
AbstractBeanDefinition afbDef = (AbstractBeanDefinition) fbDef;
@@ -798,6 +799,7 @@ protected Class<?> getTypeForFactoryBean(String beanName, RootBeanDefinition mbd
798799
}
799800
}
800801

802+
// Let's obtain a shortcut instance for an early getObjectType() call...
801803
FactoryBean<?> fb = (mbd.isSingleton() ?
802804
getSingletonFactoryBeanForTypeCheck(beanName, mbd) :
803805
getNonSingletonFactoryBeanForTypeCheck(beanName, mbd));
@@ -842,6 +844,7 @@ class Holder { Class<?> value = null; }
842844

843845
// CGLIB subclass methods hide generic parameters; look at the original user class.
844846
Class<?> fbClass = ClassUtils.getUserClass(beanClass);
847+
845848
// Find the given factory method, taking into account that in the case of
846849
// @Bean methods, there may be parameters present.
847850
ReflectionUtils.doWithMethods(fbClass,
@@ -858,6 +861,7 @@ public void doWith(Method method) {
858861
}
859862
}
860863
});
864+
861865
return (objectType.value != null && Object.class != objectType.value ? objectType.value : null);
862866
}
863867

@@ -908,6 +912,7 @@ private FactoryBean<?> getSingletonFactoryBeanForTypeCheck(String beanName, Root
908912
(mbd.getFactoryBeanName() != null && isSingletonCurrentlyInCreation(mbd.getFactoryBeanName()))) {
909913
return null;
910914
}
915+
911916
Object instance = null;
912917
try {
913918
// Mark this bean as currently in creation, even if just partially.
@@ -923,6 +928,7 @@ private FactoryBean<?> getSingletonFactoryBeanForTypeCheck(String beanName, Root
923928
// Finished partial creation of this bean.
924929
afterSingletonCreation(beanName);
925930
}
931+
926932
FactoryBean<?> fb = getFactoryBean(beanName, instance);
927933
if (bw != null) {
928934
this.factoryBeanInstanceCache.put(beanName, bw);
@@ -943,6 +949,7 @@ private FactoryBean<?> getNonSingletonFactoryBeanForTypeCheck(String beanName, R
943949
if (isPrototypeCurrentlyInCreation(beanName)) {
944950
return null;
945951
}
952+
946953
Object instance = null;
947954
try {
948955
// Mark this bean as currently in creation, even if just partially.
@@ -966,6 +973,7 @@ private FactoryBean<?> getNonSingletonFactoryBeanForTypeCheck(String beanName, R
966973
// Finished partial creation of this bean.
967974
afterPrototypeCreation(beanName);
968975
}
976+
969977
return getFactoryBean(beanName, instance);
970978
}
971979

spring-beans/src/test/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessorTests.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3543,6 +3543,7 @@ public interface CustomMap<K, V> extends Map<K, V> {
35433543
}
35443544

35453545

3546+
@SuppressWarnings("serial")
35463547
public static class CustomHashMap<K, V> extends LinkedHashMap<K, V> implements CustomMap<K, V> {
35473548
}
35483549

@@ -3551,6 +3552,7 @@ public interface CustomSet<E> extends Set<E> {
35513552
}
35523553

35533554

3555+
@SuppressWarnings("serial")
35543556
public static class CustomHashSet<E> extends LinkedHashSet<E> implements CustomSet<E> {
35553557
}
35563558

0 commit comments

Comments
 (0)