Polishing

Closes gh-26878
This commit is contained in:
Johnny Lim
2021-04-29 23:53:53 +09:00
committed by GitHub
parent 697108cc42
commit 98770b15e7
6 changed files with 7 additions and 8 deletions

View File

@@ -30,6 +30,8 @@ import org.springframework.lang.Nullable;
*/
public abstract class ValidationAnnotationUtils {
private static final Object[] EMPTY_OBJECT_ARRAY = new Object[0];
/**
* Determine any validation hints by the given annotation.
* <p>This implementation checks for {@code @javax.validation.Valid},
@@ -38,14 +40,13 @@ public abstract class ValidationAnnotationUtils {
* @param ann the annotation (potentially a validation annotation)
* @return the validation hints to apply (possibly an empty array),
* or {@code null} if this annotation does not trigger any validation
* @since 5.3.7
*/
@Nullable
public static Object[] determineValidationHints(Annotation ann) {
Class<? extends Annotation> annotationType = ann.annotationType();
String annotationName = annotationType.getName();
if ("javax.validation.Valid".equals(annotationName)) {
return new Object[0];
return EMPTY_OBJECT_ARRAY;
}
Validated validatedAnn = AnnotationUtils.getAnnotation(ann, Validated.class);
if (validatedAnn != null) {
@@ -61,7 +62,7 @@ public abstract class ValidationAnnotationUtils {
private static Object[] convertValidationHints(@Nullable Object hints) {
if (hints == null) {
return new Object[0];
return EMPTY_OBJECT_ARRAY;
}
return (hints instanceof Object[] ? (Object[]) hints : new Object[]{hints});
}