Browse Source

Consistent bridge method handling in annotation post-processors

Issue: SPR-12495
pull/709/head
Juergen Hoeller 10 years ago
parent
commit
7317457bb1
  1. 4
      spring-beans/src/main/java/org/springframework/beans/BeanUtils.java
  2. 26
      spring-beans/src/main/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessor.java

4
spring-beans/src/main/java/org/springframework/beans/BeanUtils.java

@ -395,7 +395,7 @@ public abstract class BeanUtils { @@ -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 { @@ -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();

26
spring-beans/src/main/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessor.java

@ -269,8 +269,8 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean @@ -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 @@ -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 @@ -384,15 +384,15 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean
do {
LinkedList<InjectionMetadata.InjectedElement> currElements = new LinkedList<InjectionMetadata.InjectedElement>();
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 @@ -429,9 +429,9 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean
private AnnotationAttributes findAutowiredAnnotation(AccessibleObject ao) {
for (Class<? extends Annotation> 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 @@ -442,12 +442,12 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean
* <p>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));
}
/**

Loading…
Cancel
Save