From 7317457bb18c6caecfe01145624b535dbb6f9ea6 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Mon, 22 Dec 2014 18:46:45 +0100 Subject: [PATCH] Consistent bridge method handling in annotation post-processors Issue: SPR-12495 --- .../org/springframework/beans/BeanUtils.java | 4 +-- .../AutowiredAnnotationBeanPostProcessor.java | 26 +++++++++---------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/spring-beans/src/main/java/org/springframework/beans/BeanUtils.java b/spring-beans/src/main/java/org/springframework/beans/BeanUtils.java index a8770c46da..8c03d70831 100644 --- a/spring-beans/src/main/java/org/springframework/beans/BeanUtils.java +++ b/spring-beans/src/main/java/org/springframework/beans/BeanUtils.java @@ -395,7 +395,7 @@ public abstract class BeanUtils { * @param clazz the (most specific) class to introspect for descriptors * @return the corresponding PropertyDescriptor, or {@code null} if none * @throws BeansException if PropertyDescriptor lookup fails - * @since 4.0.9 + * @since 3.2.13 */ public static PropertyDescriptor findPropertyForMethod(Method method, Class clazz) throws BeansException { Assert.notNull(method, "Method must not be null"); @@ -609,7 +609,7 @@ public abstract class BeanUtils { for (PropertyDescriptor targetPd : targetPds) { Method writeMethod = targetPd.getWriteMethod(); - if (writeMethod != null && (ignoreList == null || (!ignoreList.contains(targetPd.getName())))) { + if (writeMethod != null && (ignoreList == null || !ignoreList.contains(targetPd.getName()))) { PropertyDescriptor sourcePd = getPropertyDescriptor(source.getClass(), targetPd.getName()); if (sourcePd != null) { Method readMethod = sourcePd.getReadMethod(); diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessor.java b/spring-beans/src/main/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessor.java index 4f8013597c..d2db02c814 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessor.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessor.java @@ -269,8 +269,8 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean Constructor requiredConstructor = null; Constructor defaultConstructor = null; for (Constructor candidate : rawCandidates) { - AnnotationAttributes annotation = findAutowiredAnnotation(candidate); - if (annotation != null) { + AnnotationAttributes ann = findAutowiredAnnotation(candidate); + if (ann != null) { if (requiredConstructor != null) { throw new BeanCreationException(beanName, "Invalid autowire-marked constructor: " + candidate + @@ -281,7 +281,7 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean throw new IllegalStateException( "Autowired annotation requires at least one argument: " + candidate); } - boolean required = determineRequiredStatus(annotation); + boolean required = determineRequiredStatus(ann); if (required) { if (!candidates.isEmpty()) { throw new BeanCreationException(beanName, @@ -384,15 +384,15 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean do { LinkedList currElements = new LinkedList(); for (Field field : targetClass.getDeclaredFields()) { - AnnotationAttributes annotation = findAutowiredAnnotation(field); - if (annotation != null) { + AnnotationAttributes ann = findAutowiredAnnotation(field); + if (ann != null) { if (Modifier.isStatic(field.getModifiers())) { if (logger.isWarnEnabled()) { logger.warn("Autowired annotation is not supported on static fields: " + field); } continue; } - boolean required = determineRequiredStatus(annotation); + boolean required = determineRequiredStatus(ann); currElements.add(new AutowiredFieldElement(field, required)); } } @@ -429,9 +429,9 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean private AnnotationAttributes findAutowiredAnnotation(AccessibleObject ao) { for (Class type : this.autowiredAnnotationTypes) { - AnnotationAttributes annotation = AnnotatedElementUtils.getAnnotationAttributes(ao, type.getName()); - if (annotation != null) { - return annotation; + AnnotationAttributes ann = AnnotatedElementUtils.getAnnotationAttributes(ao, type.getName()); + if (ann != null) { + return ann; } } return null; @@ -442,12 +442,12 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean *

A 'required' dependency means that autowiring should fail when no beans * are found. Otherwise, the autowiring process will simply bypass the field * or method when no beans are found. - * @param annotation the Autowired annotation + * @param ann the Autowired annotation * @return whether the annotation indicates that a dependency is required */ - protected boolean determineRequiredStatus(AnnotationAttributes annotation) { - return (!annotation.containsKey(this.requiredParameterName) || - this.requiredParameterValue == annotation.getBoolean(this.requiredParameterName)); + protected boolean determineRequiredStatus(AnnotationAttributes ann) { + return (!ann.containsKey(this.requiredParameterName) || + this.requiredParameterValue == ann.getBoolean(this.requiredParameterName)); } /**