Skip to content

Commit b110a39

Browse files
committed
Polishing MethodValidator contract
1 parent 734d113 commit b110a39

File tree

1 file changed

+27
-35
lines changed

1 file changed

+27
-35
lines changed

spring-context/src/main/java/org/springframework/validation/method/MethodValidator.java

Lines changed: 27 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -32,24 +32,34 @@
3232
public interface MethodValidator {
3333

3434
/**
35-
* Use this method to determine the validation groups.
35+
* Determine the applicable validation groups. By default, obtained from an
36+
* {@link org.springframework.validation.annotation.Validated @Validated}
37+
* annotation on the method, or on the class level.
3638
* @param target the target Object
3739
* @param method the target method
3840
* @return the applicable validation groups as a {@code Class} array
3941
*/
4042
Class<?>[] determineValidationGroups(Object target, Method method);
4143

4244
/**
43-
* Validate the given method arguments and handle the result.
45+
* Validate the given method arguments and return validation results.
4446
* @param target the target Object
4547
* @param method the target method
4648
* @param parameters the parameters, if already created and available
4749
* @param arguments the candidate argument values to validate
48-
* @param groups validation groups via {@link #determineValidationGroups}
49-
* @throws MethodValidationException raised by default in case of validation errors.
50-
* Implementations may provide alternative handling, possibly not raise an exception
51-
* but for example inject errors into the method, or raise a different exception,
52-
* one that also implements {@link MethodValidationResult}.
50+
* @param groups validation groups from {@link #determineValidationGroups}
51+
* @return the result of validation
52+
*/
53+
MethodValidationResult validateArguments(
54+
Object target, Method method, @Nullable MethodParameter[] parameters,
55+
Object[] arguments, Class<?>[] groups);
56+
57+
/**
58+
* Delegate to {@link #validateArguments} and handle the validation result,
59+
* by default raising {@link MethodValidationException} in case of errors.
60+
* Implementations may provide alternative handling, e.g. injecting
61+
* {@link org.springframework.validation.Errors} into the method.
62+
* @throws MethodValidationException in case of unhandled errors.
5363
*/
5464
default void applyArgumentValidation(
5565
Object target, Method method, @Nullable MethodParameter[] parameters,
@@ -62,28 +72,23 @@ default void applyArgumentValidation(
6272
}
6373

6474
/**
65-
* Validate the given method arguments and return validation results.
75+
* Validate the given return value and return validation results.
6676
* @param target the target Object
6777
* @param method the target method
68-
* @param parameters the parameters, if already created and available
69-
* @param arguments the candidate argument values to validate
78+
* @param returnType the return parameter, if already created and available
79+
* @param returnValue the return value to validate
7080
* @param groups validation groups from {@link #determineValidationGroups}
7181
* @return the result of validation
7282
*/
73-
MethodValidationResult validateArguments(
74-
Object target, Method method, @Nullable MethodParameter[] parameters,
75-
Object[] arguments, Class<?>[] groups);
83+
MethodValidationResult validateReturnValue(
84+
Object target, Method method, @Nullable MethodParameter returnType,
85+
@Nullable Object returnValue, Class<?>[] groups);
7686

7787
/**
78-
* Validate the given return value and handle the results.
79-
* @param target the target Object
80-
* @param method the target method
81-
* @param returnType the return parameter, if already created and available
82-
* @param returnValue the return value to validate
83-
* @param groups validation groups from {@link #determineValidationGroups}
84-
* @throws MethodValidationException raised by default in case of validation errors.
85-
* Implementations may provide alternative handling, or raise a different exception,
86-
* one that also implements {@link MethodValidationResult}.
88+
* Delegate to {@link #validateReturnValue} and handle the validation result,
89+
* by default raising {@link MethodValidationException} in case of errors.
90+
* Implementations may provide alternative handling.
91+
* @throws MethodValidationException in case of unhandled errors.
8792
*/
8893
default void applyReturnValueValidation(
8994
Object target, Method method, @Nullable MethodParameter returnType,
@@ -95,17 +100,4 @@ default void applyReturnValueValidation(
95100
}
96101
}
97102

98-
/**
99-
* Validate the given return value and return the result of validation.
100-
* @param target the target Object
101-
* @param method the target method
102-
* @param returnType the return parameter, if already created and available
103-
* @param returnValue the return value to validate
104-
* @param groups validation groups from {@link #determineValidationGroups}
105-
* @return the result of validation
106-
*/
107-
MethodValidationResult validateReturnValue(
108-
Object target, Method method, @Nullable MethodParameter returnType,
109-
@Nullable Object returnValue, Class<?>[] groups);
110-
111103
}

0 commit comments

Comments
 (0)