Polishing
This commit is contained in:
parent
e79a9a5bff
commit
9a56a8877f
|
|
@ -234,8 +234,8 @@ public class MethodValidationAdapter implements MethodValidator {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final MethodValidationResult validateArguments(
|
public final MethodValidationResult validateArguments(
|
||||||
Object target, Method method, @Nullable MethodParameter[] parameters, Object[] arguments,
|
Object target, Method method, @Nullable MethodParameter[] parameters,
|
||||||
Class<?>[] groups) {
|
Object[] arguments, Class<?>[] groups) {
|
||||||
|
|
||||||
Set<ConstraintViolation<Object>> violations =
|
Set<ConstraintViolation<Object>> violations =
|
||||||
invokeValidatorForArguments(target, method, arguments, groups);
|
invokeValidatorForArguments(target, method, arguments, groups);
|
||||||
|
|
@ -256,23 +256,21 @@ public class MethodValidationAdapter implements MethodValidator {
|
||||||
Object target, Method method, Object[] arguments, Class<?>[] groups) {
|
Object target, Method method, Object[] arguments, Class<?>[] groups) {
|
||||||
|
|
||||||
ExecutableValidator execVal = this.validator.get().forExecutables();
|
ExecutableValidator execVal = this.validator.get().forExecutables();
|
||||||
Set<ConstraintViolation<Object>> violations;
|
|
||||||
try {
|
try {
|
||||||
violations = execVal.validateParameters(target, method, arguments, groups);
|
return execVal.validateParameters(target, method, arguments, groups);
|
||||||
}
|
}
|
||||||
catch (IllegalArgumentException ex) {
|
catch (IllegalArgumentException ex) {
|
||||||
// Probably a generic type mismatch between interface and impl as reported in SPR-12237 / HV-1011
|
// Probably a generic type mismatch between interface and impl as reported in SPR-12237 / HV-1011
|
||||||
// Let's try to find the bridged method on the implementation class...
|
// Let's try to find the bridged method on the implementation class...
|
||||||
Method bridgedMethod = BridgeMethodResolver.getMostSpecificMethod(method, target.getClass());
|
Method bridgedMethod = BridgeMethodResolver.getMostSpecificMethod(method, target.getClass());
|
||||||
violations = execVal.validateParameters(target, bridgedMethod, arguments, groups);
|
return execVal.validateParameters(target, bridgedMethod, arguments, groups);
|
||||||
}
|
}
|
||||||
return violations;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final MethodValidationResult validateReturnValue(
|
public final MethodValidationResult validateReturnValue(
|
||||||
Object target, Method method, @Nullable MethodParameter returnType, @Nullable Object returnValue,
|
Object target, Method method, @Nullable MethodParameter returnType,
|
||||||
Class<?>[] groups) {
|
@Nullable Object returnValue, Class<?>[] groups) {
|
||||||
|
|
||||||
Set<ConstraintViolation<Object>> violations =
|
Set<ConstraintViolation<Object>> violations =
|
||||||
invokeValidatorForReturnValue(target, method, returnValue, groups);
|
invokeValidatorForReturnValue(target, method, returnValue, groups);
|
||||||
|
|
@ -305,9 +303,9 @@ public class MethodValidationAdapter implements MethodValidator {
|
||||||
Map<Path.Node, ParamErrorsBuilder> nestedViolations = new LinkedHashMap<>();
|
Map<Path.Node, ParamErrorsBuilder> nestedViolations = new LinkedHashMap<>();
|
||||||
|
|
||||||
for (ConstraintViolation<Object> violation : violations) {
|
for (ConstraintViolation<Object> violation : violations) {
|
||||||
Iterator<Path.Node> itr = violation.getPropertyPath().iterator();
|
Iterator<Path.Node> nodes = violation.getPropertyPath().iterator();
|
||||||
while (itr.hasNext()) {
|
while (nodes.hasNext()) {
|
||||||
Path.Node node = itr.next();
|
Path.Node node = nodes.next();
|
||||||
|
|
||||||
MethodParameter parameter;
|
MethodParameter parameter;
|
||||||
if (node.getKind().equals(ElementKind.PARAMETER)) {
|
if (node.getKind().equals(ElementKind.PARAMETER)) {
|
||||||
|
|
@ -328,8 +326,8 @@ public class MethodValidationAdapter implements MethodValidator {
|
||||||
// https://github.com/jakartaee/validation/issues/194
|
// https://github.com/jakartaee/validation/issues/194
|
||||||
|
|
||||||
Path.Node parameterNode = node;
|
Path.Node parameterNode = node;
|
||||||
if (itr.hasNext()) {
|
if (nodes.hasNext()) {
|
||||||
node = itr.next();
|
node = nodes.next();
|
||||||
}
|
}
|
||||||
|
|
||||||
Object value;
|
Object value;
|
||||||
|
|
@ -425,7 +423,6 @@ public class MethodValidationAdapter implements MethodValidator {
|
||||||
* @return the name to use
|
* @return the name to use
|
||||||
*/
|
*/
|
||||||
String resolveName(MethodParameter parameter, @Nullable Object value);
|
String resolveName(MethodParameter parameter, @Nullable Object value);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -456,6 +453,7 @@ public class MethodValidationAdapter implements MethodValidator {
|
||||||
public ParamValidationResultBuilder(
|
public ParamValidationResultBuilder(
|
||||||
Object target, MethodParameter parameter, @Nullable Object value, @Nullable Object container,
|
Object target, MethodParameter parameter, @Nullable Object value, @Nullable Object container,
|
||||||
@Nullable Integer containerIndex, @Nullable Object containerKey) {
|
@Nullable Integer containerIndex, @Nullable Object containerKey) {
|
||||||
|
|
||||||
this.target = target;
|
this.target = target;
|
||||||
this.parameter = parameter;
|
this.parameter = parameter;
|
||||||
this.value = value;
|
this.value = value;
|
||||||
|
|
@ -473,7 +471,6 @@ public class MethodValidationAdapter implements MethodValidator {
|
||||||
this.parameter, this.value, this.resolvableErrors, this.container,
|
this.parameter, this.value, this.resolvableErrors, this.container,
|
||||||
this.containerIndex, this.containerKey);
|
this.containerIndex, this.containerKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -527,8 +524,7 @@ public class MethodValidationAdapter implements MethodValidator {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default algorithm to select an object name, as described in
|
* Default algorithm to select an object name, as described in {@link #setObjectNameResolver}.
|
||||||
* {@link #setObjectNameResolver(ObjectNameResolver)}.
|
|
||||||
*/
|
*/
|
||||||
private static class DefaultObjectNameResolver implements ObjectNameResolver {
|
private static class DefaultObjectNameResolver implements ObjectNameResolver {
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue