Skip to content

Commit

Permalink
Consistent bridge method handling in annotation post-processors
Browse files Browse the repository at this point in the history
Issue: SPR-12495
  • Loading branch information
jhoeller committed Dec 22, 2014
1 parent 61a6bc0 commit dc15070
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 18 deletions.
Expand Up @@ -396,7 +396,7 @@ public static PropertyDescriptor findPropertyForMethod(Method method) throws Bea
* @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");
Expand Down Expand Up @@ -610,7 +610,7 @@ private static void copyProperties(Object source, Object target, Class<?> editab

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();
Expand Down
Expand Up @@ -236,8 +236,8 @@ public Constructor<?>[] determineCandidateConstructors(Class<?> beanClass, Strin
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 +
Expand All @@ -248,7 +248,7 @@ public Constructor<?>[] determineCandidateConstructors(Class<?> beanClass, Strin
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,
Expand Down Expand Up @@ -322,9 +322,9 @@ public void processInjection(Object bean) throws BeansException {


private InjectionMetadata findAutowiringMetadata(String beanName, Class<?> clazz) {
// Quick check on the concurrent map first, with minimal locking.
// Fall back to class name as cache key, for backwards compatibility with custom callers.
String cacheKey = (StringUtils.hasLength(beanName) ? beanName : clazz.getName());
// Quick check on the concurrent map first, with minimal locking.
InjectionMetadata metadata = this.injectionMetadataCache.get(cacheKey);
if (InjectionMetadata.needsRefresh(metadata, clazz)) {
synchronized (this.injectionMetadataCache) {
Expand All @@ -345,15 +345,15 @@ private InjectionMetadata buildAutowiringMetadata(Class<?> clazz) {
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));
}
}
Expand Down Expand Up @@ -390,9 +390,9 @@ private InjectionMetadata buildAutowiringMetadata(Class<?> clazz) {

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;
Expand All @@ -403,12 +403,12 @@ private AnnotationAttributes findAutowiredAnnotation(AccessibleObject ao) {
* <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));
}

/**
Expand Down
Expand Up @@ -401,10 +401,9 @@ private InjectionMetadata findPersistenceMetadata(String beanName, final Class<?
}
for (Method method : targetClass.getDeclaredMethods()) {
method = BridgeMethodResolver.findBridgedMethod(method);
Method mostSpecificMethod = BridgeMethodResolver.findBridgedMethod(ClassUtils.getMostSpecificMethod(method, clazz));
if ((method.isAnnotationPresent(PersistenceContext.class) ||
method.isAnnotationPresent(PersistenceUnit.class)) &&
method.equals(mostSpecificMethod)) {
method.equals(BridgeMethodResolver.findBridgedMethod(ClassUtils.getMostSpecificMethod(method, clazz)))) {
if (Modifier.isStatic(method.getModifiers())) {
throw new IllegalStateException("Persistence annotations are not supported on static methods");
}
Expand Down

0 comments on commit dc15070

Please sign in to comment.