Skip to content

Commit dc15070

Browse files
committed
Consistent bridge method handling in annotation post-processors
Issue: SPR-12495
1 parent 61a6bc0 commit dc15070

File tree

3 files changed

+17
-18
lines changed

3 files changed

+17
-18
lines changed

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ public static PropertyDescriptor findPropertyForMethod(Method method) throws Bea
396396
* @param clazz the (most specific) class to introspect for descriptors
397397
* @return the corresponding PropertyDescriptor, or {@code null} if none
398398
* @throws BeansException if PropertyDescriptor lookup fails
399-
* @since 4.0.9
399+
* @since 3.2.13
400400
*/
401401
public static PropertyDescriptor findPropertyForMethod(Method method, Class<?> clazz) throws BeansException {
402402
Assert.notNull(method, "Method must not be null");
@@ -610,7 +610,7 @@ private static void copyProperties(Object source, Object target, Class<?> editab
610610

611611
for (PropertyDescriptor targetPd : targetPds) {
612612
Method writeMethod = targetPd.getWriteMethod();
613-
if (writeMethod != null && (ignoreList == null || (!ignoreList.contains(targetPd.getName())))) {
613+
if (writeMethod != null && (ignoreList == null || !ignoreList.contains(targetPd.getName()))) {
614614
PropertyDescriptor sourcePd = getPropertyDescriptor(source.getClass(), targetPd.getName());
615615
if (sourcePd != null) {
616616
Method readMethod = sourcePd.getReadMethod();

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

+14-14
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,8 @@ public Constructor<?>[] determineCandidateConstructors(Class<?> beanClass, Strin
236236
Constructor<?> requiredConstructor = null;
237237
Constructor<?> defaultConstructor = null;
238238
for (Constructor<?> candidate : rawCandidates) {
239-
AnnotationAttributes annotation = findAutowiredAnnotation(candidate);
240-
if (annotation != null) {
239+
AnnotationAttributes ann = findAutowiredAnnotation(candidate);
240+
if (ann != null) {
241241
if (requiredConstructor != null) {
242242
throw new BeanCreationException(beanName,
243243
"Invalid autowire-marked constructor: " + candidate +
@@ -248,7 +248,7 @@ public Constructor<?>[] determineCandidateConstructors(Class<?> beanClass, Strin
248248
throw new IllegalStateException(
249249
"Autowired annotation requires at least one argument: " + candidate);
250250
}
251-
boolean required = determineRequiredStatus(annotation);
251+
boolean required = determineRequiredStatus(ann);
252252
if (required) {
253253
if (!candidates.isEmpty()) {
254254
throw new BeanCreationException(beanName,
@@ -322,9 +322,9 @@ public void processInjection(Object bean) throws BeansException {
322322

323323

324324
private InjectionMetadata findAutowiringMetadata(String beanName, Class<?> clazz) {
325-
// Quick check on the concurrent map first, with minimal locking.
326325
// Fall back to class name as cache key, for backwards compatibility with custom callers.
327326
String cacheKey = (StringUtils.hasLength(beanName) ? beanName : clazz.getName());
327+
// Quick check on the concurrent map first, with minimal locking.
328328
InjectionMetadata metadata = this.injectionMetadataCache.get(cacheKey);
329329
if (InjectionMetadata.needsRefresh(metadata, clazz)) {
330330
synchronized (this.injectionMetadataCache) {
@@ -345,15 +345,15 @@ private InjectionMetadata buildAutowiringMetadata(Class<?> clazz) {
345345
do {
346346
LinkedList<InjectionMetadata.InjectedElement> currElements = new LinkedList<InjectionMetadata.InjectedElement>();
347347
for (Field field : targetClass.getDeclaredFields()) {
348-
AnnotationAttributes annotation = findAutowiredAnnotation(field);
349-
if (annotation != null) {
348+
AnnotationAttributes ann = findAutowiredAnnotation(field);
349+
if (ann != null) {
350350
if (Modifier.isStatic(field.getModifiers())) {
351351
if (logger.isWarnEnabled()) {
352352
logger.warn("Autowired annotation is not supported on static fields: " + field);
353353
}
354354
continue;
355355
}
356-
boolean required = determineRequiredStatus(annotation);
356+
boolean required = determineRequiredStatus(ann);
357357
currElements.add(new AutowiredFieldElement(field, required));
358358
}
359359
}
@@ -390,9 +390,9 @@ private InjectionMetadata buildAutowiringMetadata(Class<?> clazz) {
390390

391391
private AnnotationAttributes findAutowiredAnnotation(AccessibleObject ao) {
392392
for (Class<? extends Annotation> type : this.autowiredAnnotationTypes) {
393-
AnnotationAttributes annotation = AnnotatedElementUtils.getAnnotationAttributes(ao, type.getName());
394-
if (annotation != null) {
395-
return annotation;
393+
AnnotationAttributes ann = AnnotatedElementUtils.getAnnotationAttributes(ao, type.getName());
394+
if (ann != null) {
395+
return ann;
396396
}
397397
}
398398
return null;
@@ -403,12 +403,12 @@ private AnnotationAttributes findAutowiredAnnotation(AccessibleObject ao) {
403403
* <p>A 'required' dependency means that autowiring should fail when no beans
404404
* are found. Otherwise, the autowiring process will simply bypass the field
405405
* or method when no beans are found.
406-
* @param annotation the Autowired annotation
406+
* @param ann the Autowired annotation
407407
* @return whether the annotation indicates that a dependency is required
408408
*/
409-
protected boolean determineRequiredStatus(AnnotationAttributes annotation) {
410-
return (!annotation.containsKey(this.requiredParameterName) ||
411-
this.requiredParameterValue == annotation.getBoolean(this.requiredParameterName));
409+
protected boolean determineRequiredStatus(AnnotationAttributes ann) {
410+
return (!ann.containsKey(this.requiredParameterName) ||
411+
this.requiredParameterValue == ann.getBoolean(this.requiredParameterName));
412412
}
413413

414414
/**

spring-orm/src/main/java/org/springframework/orm/jpa/support/PersistenceAnnotationBeanPostProcessor.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -401,10 +401,9 @@ private InjectionMetadata findPersistenceMetadata(String beanName, final Class<?
401401
}
402402
for (Method method : targetClass.getDeclaredMethods()) {
403403
method = BridgeMethodResolver.findBridgedMethod(method);
404-
Method mostSpecificMethod = BridgeMethodResolver.findBridgedMethod(ClassUtils.getMostSpecificMethod(method, clazz));
405404
if ((method.isAnnotationPresent(PersistenceContext.class) ||
406405
method.isAnnotationPresent(PersistenceUnit.class)) &&
407-
method.equals(mostSpecificMethod)) {
406+
method.equals(BridgeMethodResolver.findBridgedMethod(ClassUtils.getMostSpecificMethod(method, clazz)))) {
408407
if (Modifier.isStatic(method.getModifiers())) {
409408
throw new IllegalStateException("Persistence annotations are not supported on static methods");
410409
}

0 commit comments

Comments
 (0)