Skip to content

Commit

Permalink
Polishing
Browse files Browse the repository at this point in the history
  • Loading branch information
jhoeller committed Jun 17, 2024
1 parent e79a9a5 commit 9a56a88
Showing 1 changed file with 13 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,8 @@ public Class<?>[] determineValidationGroups(Object target, Method method) {

@Override
public final MethodValidationResult validateArguments(
Object target, Method method, @Nullable MethodParameter[] parameters, Object[] arguments,
Class<?>[] groups) {
Object target, Method method, @Nullable MethodParameter[] parameters,
Object[] arguments, Class<?>[] groups) {

Set<ConstraintViolation<Object>> violations =
invokeValidatorForArguments(target, method, arguments, groups);
Expand All @@ -256,23 +256,21 @@ public final Set<ConstraintViolation<Object>> invokeValidatorForArguments(
Object target, Method method, Object[] arguments, Class<?>[] groups) {

ExecutableValidator execVal = this.validator.get().forExecutables();
Set<ConstraintViolation<Object>> violations;
try {
violations = execVal.validateParameters(target, method, arguments, groups);
return execVal.validateParameters(target, method, arguments, groups);
}
catch (IllegalArgumentException ex) {
// 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...
Method bridgedMethod = BridgeMethodResolver.getMostSpecificMethod(method, target.getClass());
violations = execVal.validateParameters(target, bridgedMethod, arguments, groups);
return execVal.validateParameters(target, bridgedMethod, arguments, groups);
}
return violations;
}

@Override
public final MethodValidationResult validateReturnValue(
Object target, Method method, @Nullable MethodParameter returnType, @Nullable Object returnValue,
Class<?>[] groups) {
Object target, Method method, @Nullable MethodParameter returnType,
@Nullable Object returnValue, Class<?>[] groups) {

Set<ConstraintViolation<Object>> violations =
invokeValidatorForReturnValue(target, method, returnValue, groups);
Expand Down Expand Up @@ -305,9 +303,9 @@ private MethodValidationResult adaptViolations(
Map<Path.Node, ParamErrorsBuilder> nestedViolations = new LinkedHashMap<>();

for (ConstraintViolation<Object> violation : violations) {
Iterator<Path.Node> itr = violation.getPropertyPath().iterator();
while (itr.hasNext()) {
Path.Node node = itr.next();
Iterator<Path.Node> nodes = violation.getPropertyPath().iterator();
while (nodes.hasNext()) {
Path.Node node = nodes.next();

MethodParameter parameter;
if (node.getKind().equals(ElementKind.PARAMETER)) {
Expand All @@ -328,8 +326,8 @@ else if (node.getKind().equals(ElementKind.RETURN_VALUE)) {
// https://github.com/jakartaee/validation/issues/194

Path.Node parameterNode = node;
if (itr.hasNext()) {
node = itr.next();
if (nodes.hasNext()) {
node = nodes.next();
}

Object value;
Expand Down Expand Up @@ -425,7 +423,6 @@ public interface ObjectNameResolver {
* @return the name to use
*/
String resolveName(MethodParameter parameter, @Nullable Object value);

}


Expand Down Expand Up @@ -456,6 +453,7 @@ private final class ParamValidationResultBuilder {
public ParamValidationResultBuilder(
Object target, MethodParameter parameter, @Nullable Object value, @Nullable Object container,
@Nullable Integer containerIndex, @Nullable Object containerKey) {

this.target = target;
this.parameter = parameter;
this.value = value;
Expand All @@ -473,7 +471,6 @@ public ParameterValidationResult build() {
this.parameter, this.value, this.resolvableErrors, this.container,
this.containerIndex, this.containerKey);
}

}


Expand Down Expand Up @@ -527,8 +524,7 @@ public ParameterErrors build() {


/**
* Default algorithm to select an object name, as described in
* {@link #setObjectNameResolver(ObjectNameResolver)}.
* Default algorithm to select an object name, as described in {@link #setObjectNameResolver}.
*/
private static class DefaultObjectNameResolver implements ObjectNameResolver {

Expand Down

0 comments on commit 9a56a88

Please sign in to comment.