Merge branch '5.3.x'

This commit is contained in:
Sam Brannen
2022-10-11 19:39:20 +02:00
2 changed files with 19 additions and 4 deletions

View File

@@ -18,7 +18,9 @@ package org.springframework.core.annotation;
import java.lang.annotation.Annotation;
import java.lang.annotation.Repeatable;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.Map;
import org.springframework.lang.Nullable;
@@ -131,6 +133,19 @@ public abstract class RepeatableContainers {
return NoRepeatableContainers.INSTANCE;
}
private static Object invokeAnnotationMethod(Annotation annotation, Method method) {
if (Proxy.isProxyClass(annotation.getClass())) {
try {
InvocationHandler handler = Proxy.getInvocationHandler(annotation);
return handler.invoke(annotation, method, null);
}
catch (Throwable ex) {
// ignore and fall back to reflection below
}
}
return ReflectionUtils.invokeMethod(method, annotation);
}
/**
* Standard {@link RepeatableContainers} implementation that searches using
@@ -153,7 +168,7 @@ public abstract class RepeatableContainers {
Annotation[] findRepeatedAnnotations(Annotation annotation) {
Method method = getRepeatedAnnotationsMethod(annotation.annotationType());
if (method != null) {
return (Annotation[]) ReflectionUtils.invokeMethod(method, annotation);
return (Annotation[]) invokeAnnotationMethod(annotation, method);
}
return super.findRepeatedAnnotations(annotation);
}
@@ -240,7 +255,7 @@ public abstract class RepeatableContainers {
@Nullable
Annotation[] findRepeatedAnnotations(Annotation annotation) {
if (this.container.isAssignableFrom(annotation.annotationType())) {
return (Annotation[]) ReflectionUtils.invokeMethod(this.valueMethod, annotation);
return (Annotation[]) invokeAnnotationMethod(annotation, this.valueMethod);
}
return super.findRepeatedAnnotations(annotation);
}