Skip to content

Commit 192113d

Browse files
committed
Correctly determine and propagate validation hints to DataBinder
Issue: SPR-17073 (cherry picked from commit 3c65c17)
1 parent f89511e commit 192113d

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/ModelAttributeMethodArgumentResolver.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -271,13 +271,17 @@ private boolean hasErrorsArgument(MethodParameter parameter) {
271271
}
272272

273273
private void validateIfApplicable(WebExchangeDataBinder binder, MethodParameter parameter) {
274-
Annotation[] annotations = parameter.getParameterAnnotations();
275-
for (Annotation ann : annotations) {
276-
Validated validAnnot = AnnotationUtils.getAnnotation(ann, Validated.class);
277-
if (validAnnot != null || ann.annotationType().getSimpleName().startsWith("Valid")) {
278-
Object hints = (validAnnot != null ? validAnnot.value() : AnnotationUtils.getValue(ann));
279-
Object hintArray = (hints instanceof Object[] ? (Object[]) hints : new Object[] {hints});
280-
binder.validate(hintArray);
274+
for (Annotation ann : parameter.getParameterAnnotations()) {
275+
Validated validatedAnn = AnnotationUtils.getAnnotation(ann, Validated.class);
276+
if (validatedAnn != null || ann.annotationType().getSimpleName().startsWith("Valid")) {
277+
Object hints = (validatedAnn != null ? validatedAnn.value() : AnnotationUtils.getValue(ann));
278+
if (hints != null) {
279+
Object[] validationHints = (hints instanceof Object[] ? (Object[]) hints : new Object[] {hints});
280+
binder.validate(validationHints);
281+
}
282+
else {
283+
binder.validate();
284+
}
281285
}
282286
}
283287
}

0 commit comments

Comments
 (0)