@@ -135,21 +135,21 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
135
135
* Dependency types to ignore on dependency check and autowire, as Set of
136
136
* Class objects: for example, String. Default is none.
137
137
*/
138
- private final Set <Class > ignoredDependencyTypes = new HashSet <Class >();
138
+ private final Set <Class <?>> ignoredDependencyTypes = new HashSet <Class <?> >();
139
139
140
140
/**
141
141
* Dependency interfaces to ignore on dependency check and autowire, as Set of
142
142
* Class objects. By default, only the BeanFactory interface is ignored.
143
143
*/
144
- private final Set <Class > ignoredDependencyInterfaces = new HashSet <Class >();
144
+ private final Set <Class <?>> ignoredDependencyInterfaces = new HashSet <Class <?> >();
145
145
146
146
/** Cache of unfinished FactoryBean instances: FactoryBean name --> BeanWrapper */
147
147
private final Map <String , BeanWrapper > factoryBeanInstanceCache =
148
148
new ConcurrentHashMap <String , BeanWrapper >(16 );
149
149
150
150
/** Cache of filtered PropertyDescriptors: bean Class -> PropertyDescriptor array */
151
- private final Map <Class , PropertyDescriptor []> filteredPropertyDescriptorsCache =
152
- new ConcurrentHashMap <Class , PropertyDescriptor []>(64 );
151
+ private final Map <Class <?> , PropertyDescriptor []> filteredPropertyDescriptorsCache =
152
+ new ConcurrentHashMap <Class <?> , PropertyDescriptor []>(64 );
153
153
154
154
155
155
/**
@@ -506,7 +506,7 @@ protected Object doCreateBean(final String beanName, final RootBeanDefinition mb
506
506
logger .debug ("Eagerly caching bean '" + beanName +
507
507
"' to allow for resolving potential circular references" );
508
508
}
509
- addSingletonFactory (beanName , new ObjectFactory () {
509
+ addSingletonFactory (beanName , new ObjectFactory < Object > () {
510
510
public Object getObject () throws BeansException {
511
511
return getEarlyBeanReference (beanName , mbd , bean );
512
512
}
@@ -634,9 +634,9 @@ protected Class<?> getTypeForFactoryMethod(String beanName, RootBeanDefinition m
634
634
635
635
// If all factory methods have the same return type, return that type.
636
636
// Can't clearly figure out exact method due to type converting / autowiring!
637
+ Class <?> commonType = null ;
637
638
int minNrOfArgs = mbd .getConstructorArgumentValues ().getArgumentCount ();
638
639
Method [] candidates = ReflectionUtils .getUniqueDeclaredMethods (factoryClass );
639
- Set <Class <?>> returnTypes = new HashSet <Class <?>>(1 );
640
640
for (Method factoryMethod : candidates ) {
641
641
if (Modifier .isStatic (factoryMethod .getModifiers ()) == isStatic &&
642
642
factoryMethod .getName ().equals (mbd .getFactoryMethodName ()) &&
@@ -669,7 +669,7 @@ protected Class<?> getTypeForFactoryMethod(String beanName, RootBeanDefinition m
669
669
Class <?> returnType = AutowireUtils .resolveReturnTypeForFactoryMethod (
670
670
factoryMethod , args , getBeanClassLoader ());
671
671
if (returnType != null ) {
672
- returnTypes . add (returnType );
672
+ commonType = ClassUtils . determineCommonAncestor (returnType , commonType );
673
673
}
674
674
}
675
675
catch (Throwable ex ) {
@@ -679,14 +679,14 @@ protected Class<?> getTypeForFactoryMethod(String beanName, RootBeanDefinition m
679
679
}
680
680
}
681
681
else {
682
- returnTypes . add (factoryMethod .getReturnType ());
682
+ commonType = ClassUtils . determineCommonAncestor (factoryMethod .getReturnType (), commonType );
683
683
}
684
684
}
685
685
}
686
686
687
- if (returnTypes . size () == 1 ) {
687
+ if (commonType != null ) {
688
688
// Clear return type found: all factory methods return same type.
689
- return returnTypes . iterator (). next () ;
689
+ return commonType ;
690
690
}
691
691
else {
692
692
// Ambiguous return types found: return null to indicate "not determinable".
@@ -788,11 +788,11 @@ protected Object getEarlyBeanReference(String beanName, RootBeanDefinition mbd,
788
788
* @return the FactoryBean instance, or {@code null} to indicate
789
789
* that we couldn't obtain a shortcut FactoryBean instance
790
790
*/
791
- private FactoryBean getSingletonFactoryBeanForTypeCheck (String beanName , RootBeanDefinition mbd ) {
791
+ private FactoryBean <?> getSingletonFactoryBeanForTypeCheck (String beanName , RootBeanDefinition mbd ) {
792
792
synchronized (getSingletonMutex ()) {
793
793
BeanWrapper bw = this .factoryBeanInstanceCache .get (beanName );
794
794
if (bw != null ) {
795
- return (FactoryBean ) bw .getWrappedInstance ();
795
+ return (FactoryBean <?> ) bw .getWrappedInstance ();
796
796
}
797
797
if (isSingletonCurrentlyInCreation (beanName )) {
798
798
return null ;
@@ -812,7 +812,7 @@ private FactoryBean getSingletonFactoryBeanForTypeCheck(String beanName, RootBea
812
812
// Finished partial creation of this bean.
813
813
afterSingletonCreation (beanName );
814
814
}
815
- FactoryBean fb = getFactoryBean (beanName , instance );
815
+ FactoryBean <?> fb = getFactoryBean (beanName , instance );
816
816
if (bw != null ) {
817
817
this .factoryBeanInstanceCache .put (beanName , bw );
818
818
}
@@ -829,7 +829,7 @@ private FactoryBean getSingletonFactoryBeanForTypeCheck(String beanName, RootBea
829
829
* @return the FactoryBean instance, or {@code null} to indicate
830
830
* that we couldn't obtain a shortcut FactoryBean instance
831
831
*/
832
- private FactoryBean getNonSingletonFactoryBeanForTypeCheck (String beanName , RootBeanDefinition mbd ) {
832
+ private FactoryBean <?> getNonSingletonFactoryBeanForTypeCheck (String beanName , RootBeanDefinition mbd ) {
833
833
if (isPrototypeCurrentlyInCreation (beanName )) {
834
834
return null ;
835
835
}
@@ -972,7 +972,7 @@ protected BeanWrapper createBeanInstance(String beanName, RootBeanDefinition mbd
972
972
}
973
973
974
974
// Need to determine the constructor...
975
- Constructor [] ctors = determineConstructorsFromBeanPostProcessors (beanClass , beanName );
975
+ Constructor <?> [] ctors = determineConstructorsFromBeanPostProcessors (beanClass , beanName );
976
976
if (ctors != null ||
977
977
mbd .getResolvedAutowireMode () == RootBeanDefinition .AUTOWIRE_CONSTRUCTOR ||
978
978
mbd .hasConstructorArgumentValues () || !ObjectUtils .isEmpty (args )) {
@@ -992,14 +992,14 @@ protected BeanWrapper createBeanInstance(String beanName, RootBeanDefinition mbd
992
992
* @throws org.springframework.beans.BeansException in case of errors
993
993
* @see org.springframework.beans.factory.config.SmartInstantiationAwareBeanPostProcessor#determineCandidateConstructors
994
994
*/
995
- protected Constructor [] determineConstructorsFromBeanPostProcessors (Class <?> beanClass , String beanName )
995
+ protected Constructor <?> [] determineConstructorsFromBeanPostProcessors (Class <?> beanClass , String beanName )
996
996
throws BeansException {
997
997
998
998
if (beanClass != null && hasInstantiationAwareBeanPostProcessors ()) {
999
999
for (BeanPostProcessor bp : getBeanPostProcessors ()) {
1000
1000
if (bp instanceof SmartInstantiationAwareBeanPostProcessor ) {
1001
1001
SmartInstantiationAwareBeanPostProcessor ibp = (SmartInstantiationAwareBeanPostProcessor ) bp ;
1002
- Constructor [] ctors = ibp .determineCandidateConstructors (beanClass , beanName );
1002
+ Constructor <?> [] ctors = ibp .determineCandidateConstructors (beanClass , beanName );
1003
1003
if (ctors != null ) {
1004
1004
return ctors ;
1005
1005
}
@@ -1070,7 +1070,7 @@ protected BeanWrapper instantiateUsingFactoryMethod(
1070
1070
* @return BeanWrapper for the new instance
1071
1071
*/
1072
1072
protected BeanWrapper autowireConstructor (
1073
- String beanName , RootBeanDefinition mbd , Constructor [] ctors , Object [] explicitArgs ) {
1073
+ String beanName , RootBeanDefinition mbd , Constructor <?> [] ctors , Object [] explicitArgs ) {
1074
1074
1075
1075
return new ConstructorResolver (this ).autowireConstructor (beanName , mbd , ctors , explicitArgs );
1076
1076
}
0 commit comments