Skip to content

Commit 518c85b

Browse files
committed
Support synthesized annotations in MethodParameter
1 parent 1afc938 commit 518c85b

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

spring-core/src/main/java/org/springframework/core/MethodParameter.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import java.util.HashMap;
2727
import java.util.Map;
2828

29+
import org.springframework.core.annotation.AnnotationUtils;
2930
import org.springframework.util.Assert;
3031

3132
/**
@@ -36,6 +37,7 @@
3637
* @author Juergen Hoeller
3738
* @author Rob Harrop
3839
* @author Andy Clement
40+
* @author Sam Brannen
3941
* @since 2.0
4042
* @see GenericCollectionTypeResolver
4143
*/
@@ -386,7 +388,7 @@ public Type getNestedGenericParameterType() {
386388
* Return the annotations associated with the target method/constructor itself.
387389
*/
388390
public Annotation[] getMethodAnnotations() {
389-
return getAnnotatedElement().getAnnotations();
391+
return AnnotationUtils.synthesizeAnnotationArray(getAnnotatedElement().getAnnotations(), getAnnotatedElement());
390392
}
391393

392394
/**
@@ -395,7 +397,8 @@ public Annotation[] getMethodAnnotations() {
395397
* @return the annotation object, or {@code null} if not found
396398
*/
397399
public <T extends Annotation> T getMethodAnnotation(Class<T> annotationType) {
398-
return getAnnotatedElement().getAnnotation(annotationType);
400+
AnnotatedElement element = getAnnotatedElement();
401+
return AnnotationUtils.synthesizeAnnotation(element.getAnnotation(annotationType), element);
399402
}
400403

401404
/**
@@ -406,7 +409,8 @@ public Annotation[] getParameterAnnotations() {
406409
Annotation[][] annotationArray = (this.method != null ?
407410
this.method.getParameterAnnotations() : this.constructor.getParameterAnnotations());
408411
if (this.parameterIndex >= 0 && this.parameterIndex < annotationArray.length) {
409-
this.parameterAnnotations = annotationArray[this.parameterIndex];
412+
this.parameterAnnotations = AnnotationUtils.synthesizeAnnotationArray(
413+
annotationArray[this.parameterIndex], getAnnotatedElement());
410414
}
411415
else {
412416
this.parameterAnnotations = new Annotation[0];

0 commit comments

Comments
 (0)