@@ -233,8 +233,8 @@ public Constructor<?>[] determineCandidateConstructors(Class<?> beanClass, Strin
233
233
Constructor <?> requiredConstructor = null ;
234
234
Constructor <?> defaultConstructor = null ;
235
235
for (Constructor <?> candidate : rawCandidates ) {
236
- Annotation annotation = findAutowiredAnnotation (candidate );
237
- if (annotation != null ) {
236
+ Annotation ann = findAutowiredAnnotation (candidate );
237
+ if (ann != null ) {
238
238
if (requiredConstructor != null ) {
239
239
throw new BeanCreationException (beanName ,
240
240
"Invalid autowire-marked constructor: " + candidate +
@@ -245,7 +245,7 @@ public Constructor<?>[] determineCandidateConstructors(Class<?> beanClass, Strin
245
245
throw new IllegalStateException (
246
246
"Autowired annotation requires at least one argument: " + candidate );
247
247
}
248
- boolean required = determineRequiredStatus (annotation );
248
+ boolean required = determineRequiredStatus (ann );
249
249
if (required ) {
250
250
if (!candidates .isEmpty ()) {
251
251
throw new BeanCreationException (beanName ,
@@ -319,9 +319,9 @@ public void processInjection(Object bean) throws BeansException {
319
319
320
320
321
321
private InjectionMetadata findAutowiringMetadata (String beanName , Class <?> clazz ) {
322
- // Quick check on the concurrent map first, with minimal locking.
323
322
// Fall back to class name as cache key, for backwards compatibility with custom callers.
324
323
String cacheKey = (StringUtils .hasLength (beanName ) ? beanName : clazz .getName ());
324
+ // Quick check on the concurrent map first, with minimal locking.
325
325
InjectionMetadata metadata = this .injectionMetadataCache .get (cacheKey );
326
326
if (InjectionMetadata .needsRefresh (metadata , clazz )) {
327
327
synchronized (this .injectionMetadataCache ) {
@@ -342,23 +342,25 @@ private InjectionMetadata buildAutowiringMetadata(Class<?> clazz) {
342
342
do {
343
343
LinkedList <InjectionMetadata .InjectedElement > currElements = new LinkedList <InjectionMetadata .InjectedElement >();
344
344
for (Field field : targetClass .getDeclaredFields ()) {
345
- Annotation annotation = findAutowiredAnnotation (field );
346
- if (annotation != null ) {
345
+ Annotation ann = findAutowiredAnnotation (field );
346
+ if (ann != null ) {
347
347
if (Modifier .isStatic (field .getModifiers ())) {
348
348
if (logger .isWarnEnabled ()) {
349
349
logger .warn ("Autowired annotation is not supported on static fields: " + field );
350
350
}
351
351
continue ;
352
352
}
353
- boolean required = determineRequiredStatus (annotation );
353
+ boolean required = determineRequiredStatus (ann );
354
354
currElements .add (new AutowiredFieldElement (field , required ));
355
355
}
356
356
}
357
357
for (Method method : targetClass .getDeclaredMethods ()) {
358
+ Annotation ann = null ;
358
359
Method bridgedMethod = BridgeMethodResolver .findBridgedMethod (method );
359
- Annotation annotation = BridgeMethodResolver .isVisibilityBridgeMethodPair (method , bridgedMethod ) ?
360
- findAutowiredAnnotation (bridgedMethod ) : findAutowiredAnnotation (method );
361
- if (annotation != null && method .equals (ClassUtils .getMostSpecificMethod (method , clazz ))) {
360
+ if (BridgeMethodResolver .isVisibilityBridgeMethodPair (method , bridgedMethod )) {
361
+ ann = findAutowiredAnnotation (bridgedMethod );
362
+ }
363
+ if (ann != null && method .equals (ClassUtils .getMostSpecificMethod (method , clazz ))) {
362
364
if (Modifier .isStatic (method .getModifiers ())) {
363
365
if (logger .isWarnEnabled ()) {
364
366
logger .warn ("Autowired annotation is not supported on static methods: " + method );
@@ -370,8 +372,8 @@ private InjectionMetadata buildAutowiringMetadata(Class<?> clazz) {
370
372
logger .warn ("Autowired annotation should be used on methods with actual parameters: " + method );
371
373
}
372
374
}
373
- boolean required = determineRequiredStatus (annotation );
374
- PropertyDescriptor pd = BeanUtils .findPropertyForMethod (method );
375
+ boolean required = determineRequiredStatus (ann );
376
+ PropertyDescriptor pd = BeanUtils .findPropertyForMethod (bridgedMethod , clazz );
375
377
currElements .add (new AutowiredMethodElement (method , required , pd ));
376
378
}
377
379
}
@@ -385,9 +387,9 @@ private InjectionMetadata buildAutowiringMetadata(Class<?> clazz) {
385
387
386
388
private Annotation findAutowiredAnnotation (AccessibleObject ao ) {
387
389
for (Class <? extends Annotation > type : this .autowiredAnnotationTypes ) {
388
- Annotation annotation = AnnotationUtils .getAnnotation (ao , type );
389
- if (annotation != null ) {
390
- return annotation ;
390
+ Annotation ann = AnnotationUtils .getAnnotation (ao , type );
391
+ if (ann != null ) {
392
+ return ann ;
391
393
}
392
394
}
393
395
return null ;
@@ -412,21 +414,21 @@ protected <T> Map<String, T> findAutowireCandidates(Class<T> type) throws BeansE
412
414
* <p>A 'required' dependency means that autowiring should fail when no beans
413
415
* are found. Otherwise, the autowiring process will simply bypass the field
414
416
* or method when no beans are found.
415
- * @param annotation the Autowired annotation
417
+ * @param ann the Autowired annotation
416
418
* @return whether the annotation indicates that a dependency is required
417
419
*/
418
- protected boolean determineRequiredStatus (Annotation annotation ) {
420
+ protected boolean determineRequiredStatus (Annotation ann ) {
419
421
try {
420
- Method method = ReflectionUtils .findMethod (annotation .annotationType (), this .requiredParameterName );
422
+ Method method = ReflectionUtils .findMethod (ann .annotationType (), this .requiredParameterName );
421
423
if (method == null ) {
422
- // annotations like @Inject and @Value don't have a method (attribute) named "required"
424
+ // Annotations like @Inject and @Value don't have a method (attribute) named "required"
423
425
// -> default to required status
424
426
return true ;
425
427
}
426
- return (this .requiredParameterValue == (Boolean ) ReflectionUtils .invokeMethod (method , annotation ));
428
+ return (this .requiredParameterValue == (Boolean ) ReflectionUtils .invokeMethod (method , ann ));
427
429
}
428
430
catch (Exception ex ) {
429
- // an exception was thrown during reflective invocation of the required attribute
431
+ // An exception was thrown during reflective invocation of the required attribute
430
432
// -> default to required status
431
433
return true ;
432
434
}
0 commit comments