Consistently find @⁠Validated as a meta-annotation at arbitrary depths

Prior to this commit, ValidationAnnotationUtils looked up @⁠Validated
as a meta-annotation at arbitrary depths (e.g., when used as a
meta-meta-annotation) in determineValidationGroups() but only as a
"directly present" meta-annotation in determineValidationHints().

For consistency, this commit revises determineValidationHints() so that
it finds @⁠Validated as a meta-annotation at arbitrary depths as well.

Closes gh-36274
This commit is contained in:
Sam Brannen
2026-02-11 16:00:25 +01:00
parent 62e590a437
commit 2d3a2c5cbd
2 changed files with 200 additions and 3 deletions
@@ -27,7 +27,8 @@ import org.springframework.core.annotation.AnnotationUtils;
/**
* Utility class for handling validation annotations.
* Mainly for internal use within the framework.
*
* <p>Mainly for internal use within the framework.
*
* @author Christoph Dreis
* @author Juergen Hoeller
@@ -41,7 +42,7 @@ public abstract class ValidationAnnotationUtils {
/**
* Determine any validation hints by the given annotation.
* Determine any validation hints for the given annotation.
* <p>This implementation checks for Spring's
* {@link org.springframework.validation.annotation.Validated},
* {@code @jakarta.validation.Valid}, and custom annotations whose
@@ -62,7 +63,7 @@ public abstract class ValidationAnnotationUtils {
return EMPTY_OBJECT_ARRAY;
}
// Meta presence of @Validated ?
Validated validatedAnn = AnnotationUtils.getAnnotation(ann, Validated.class);
Validated validatedAnn = AnnotationUtils.findAnnotation(annotationType, Validated.class);
if (validatedAnn != null) {
return validatedAnn.value();
}