@@ -220,7 +220,7 @@ public int getOrder() {
220220	}
221221
222222	@ Override 
223- 	public  void  setBeanFactory (BeanFactory  beanFactory ) throws   BeansException   {
223+ 	public  void  setBeanFactory (BeanFactory  beanFactory ) {
224224		if  (!(beanFactory  instanceof  ConfigurableListableBeanFactory )) {
225225			throw  new  IllegalArgumentException (
226226					"AutowiredAnnotationBeanPostProcessor requires a ConfigurableListableBeanFactory" );
@@ -238,7 +238,10 @@ public void postProcessMergedBeanDefinition(RootBeanDefinition beanDefinition, C
238238	}
239239
240240	@ Override 
241- 	public  Constructor <?>[] determineCandidateConstructors (Class <?> beanClass , final  String  beanName ) throws  BeansException  {
241+ 	public  Constructor <?>[] determineCandidateConstructors (Class <?> beanClass , final  String  beanName )
242+ 			throws  BeanCreationException  {
243+ 
244+ 		// Let's check for lookup methods here.. 
242245		if  (!this .lookupMethodsChecked .contains (beanName )) {
243246			ReflectionUtils .doWithMethods (beanClass , new  ReflectionUtils .MethodCallback () {
244247				@ Override 
@@ -263,10 +266,19 @@ public void doWith(Method method) throws IllegalArgumentException, IllegalAccess
263266		// Quick check on the concurrent map first, with minimal locking. 
264267		Constructor <?>[] candidateConstructors  = this .candidateConstructorsCache .get (beanClass );
265268		if  (candidateConstructors  == null ) {
269+ 			// Fully synchronized resolution now... 
266270			synchronized  (this .candidateConstructorsCache ) {
267271				candidateConstructors  = this .candidateConstructorsCache .get (beanClass );
268272				if  (candidateConstructors  == null ) {
269- 					Constructor <?>[] rawCandidates  = beanClass .getDeclaredConstructors ();
273+ 					Constructor <?>[] rawCandidates ;
274+ 					try  {
275+ 						rawCandidates  = beanClass .getDeclaredConstructors ();
276+ 					}
277+ 					catch  (Throwable  ex ) {
278+ 						throw  new  BeanCreationException (beanName ,
279+ 								"Resolution of declared constructors on bean Class ["  + beanClass .getName () +
280+ 								"] from ClassLoader ["  + beanClass .getClassLoader () + "] failed" , ex );
281+ 					}
270282					List <Constructor <?>> candidates  = new  ArrayList <Constructor <?>>(rawCandidates .length );
271283					Constructor <?> requiredConstructor  = null ;
272284					Constructor <?> defaultConstructor  = null ;
@@ -320,9 +332,9 @@ else if (candidate.getParameterTypes().length == 0) {
320332							}
321333							else  if  (candidates .size () == 1  && logger .isWarnEnabled ()) {
322334								logger .warn ("Inconsistent constructor declaration on bean with name '"  + beanName  +
323- 										"': single autowire-marked constructor flagged as optional - this constructor  "  +
324- 										"is effectively required since there is no default constructor to fall back to:  "  +
325- 										candidates .get (0 ));
335+ 										"': single autowire-marked constructor flagged as optional - "  +
336+ 										"this constructor  is effectively required since there is no "  +
337+ 										"default constructor to fall back to: "  +  candidates .get (0 ));
326338							}
327339						}
328340						candidateConstructors  = candidates .toArray (new  Constructor <?>[candidates .size ()]);
@@ -342,7 +354,7 @@ else if (rawCandidates.length == 1 && rawCandidates[0].getParameterTypes().lengt
342354
343355	@ Override 
344356	public  PropertyValues  postProcessPropertyValues (
345- 			PropertyValues  pvs , PropertyDescriptor [] pds , Object  bean , String  beanName ) throws  BeansException  {
357+ 			PropertyValues  pvs , PropertyDescriptor [] pds , Object  bean , String  beanName ) throws  BeanCreationException  {
346358
347359		InjectionMetadata  metadata  = findAutowiringMetadata (beanName , bean .getClass (), pvs );
348360		try  {
@@ -361,9 +373,9 @@ public PropertyValues postProcessPropertyValues(
361373	 * 'Native' processing method for direct calls with an arbitrary target instance, 
362374	 * resolving all of its fields and methods which are annotated with {@code @Autowired}. 
363375	 * @param bean the target instance to process 
364- 	 * @throws BeansException  if autowiring failed 
376+ 	 * @throws BeanCreationException  if autowiring failed 
365377	 */ 
366- 	public  void  processInjection (Object  bean ) throws  BeansException  {
378+ 	public  void  processInjection (Object  bean ) throws  BeanCreationException  {
367379		Class <?> clazz  = bean .getClass ();
368380		InjectionMetadata  metadata  = findAutowiringMetadata (clazz .getName (), clazz , null );
369381		try  {
@@ -373,7 +385,8 @@ public void processInjection(Object bean) throws BeansException {
373385			throw  ex ;
374386		}
375387		catch  (Throwable  ex ) {
376- 			throw  new  BeanCreationException ("Injection of autowired dependencies failed for class ["  + clazz  + "]" , ex );
388+ 			throw  new  BeanCreationException (
389+ 					"Injection of autowired dependencies failed for class ["  + clazz  + "]" , ex );
377390		}
378391	}
379392
@@ -446,7 +459,8 @@ public void doWith(Method method) throws IllegalArgumentException, IllegalAccess
446459						}
447460						if  (method .getParameterTypes ().length  == 0 ) {
448461							if  (logger .isWarnEnabled ()) {
449- 								logger .warn ("Autowired annotation should be used on methods with parameters: "  + method );
462+ 								logger .warn ("Autowired annotation should only be used on methods with parameters: "  +
463+ 										method );
450464							}
451465						}
452466						boolean  required  = determineRequiredStatus (ann );
@@ -629,15 +643,15 @@ protected void inject(Object bean, String beanName, PropertyValues pvs) throws T
629643				Class <?>[] paramTypes  = method .getParameterTypes ();
630644				arguments  = new  Object [paramTypes .length ];
631645				DependencyDescriptor [] descriptors  = new  DependencyDescriptor [paramTypes .length ];
632- 				Set <String > autowiredBeanNames  = new  LinkedHashSet <String >(paramTypes .length );
646+ 				Set <String > autowiredBeans  = new  LinkedHashSet <String >(paramTypes .length );
633647				TypeConverter  typeConverter  = beanFactory .getTypeConverter ();
634648				for  (int  i  = 0 ; i  < arguments .length ; i ++) {
635649					MethodParameter  methodParam  = new  MethodParameter (method , i );
636650					DependencyDescriptor  currDesc  = new  DependencyDescriptor (methodParam , this .required );
637651					currDesc .setContainingClass (bean .getClass ());
638652					descriptors [i ] = currDesc ;
639653					try  {
640- 						Object  arg  = beanFactory .resolveDependency (currDesc , beanName , autowiredBeanNames , typeConverter );
654+ 						Object  arg  = beanFactory .resolveDependency (currDesc , beanName , autowiredBeans , typeConverter );
641655						if  (arg  == null  && !this .required ) {
642656							arguments  = null ;
643657							break ;
@@ -655,9 +669,9 @@ protected void inject(Object bean, String beanName, PropertyValues pvs) throws T
655669							for  (int  i  = 0 ; i  < arguments .length ; i ++) {
656670								this .cachedMethodArguments [i ] = descriptors [i ];
657671							}
658- 							registerDependentBeans (beanName , autowiredBeanNames );
659- 							if  (autowiredBeanNames .size () == paramTypes .length ) {
660- 								Iterator <String > it  = autowiredBeanNames .iterator ();
672+ 							registerDependentBeans (beanName , autowiredBeans );
673+ 							if  (autowiredBeans .size () == paramTypes .length ) {
674+ 								Iterator <String > it  = autowiredBeans .iterator ();
661675								for  (int  i  = 0 ; i  < paramTypes .length ; i ++) {
662676									String  autowiredBeanName  = it .next ();
663677									if  (beanFactory .containsBean (autowiredBeanName )) {
@@ -706,19 +720,19 @@ private Object[] resolveCachedArguments(String beanName) {
706720	@ SuppressWarnings ("serial" )
707721	private  static  class  ShortcutDependencyDescriptor  extends  DependencyDescriptor  {
708722
709- 		private  final  String  shortcutName ;
723+ 		private  final  String  shortcut ;
710724
711725		private  final  Class <?> requiredType ;
712726
713- 		public  ShortcutDependencyDescriptor (DependencyDescriptor  original , String  shortcutName , Class <?> requiredType ) {
727+ 		public  ShortcutDependencyDescriptor (DependencyDescriptor  original , String  shortcut , Class <?> requiredType ) {
714728			super (original );
715- 			this .shortcutName  = shortcutName ;
729+ 			this .shortcut  = shortcut ;
716730			this .requiredType  = requiredType ;
717731		}
718732
719733		@ Override 
720734		public  Object  resolveShortcut (BeanFactory  beanFactory ) {
721- 			return  resolveCandidate (this .shortcutName , this .requiredType , beanFactory );
735+ 			return  resolveCandidate (this .shortcut , this .requiredType , beanFactory );
722736		}
723737	}
724738
0 commit comments