| When validating method parameters where a groupsequence is in place, cascaded constraints do not cause the validator to halt after validating that group. Given the following setup:
interface Group1 {}
interface Group2 {}
@GroupSequence({Group1.class, Group2.class})
interface CompoundGroup {}
class CompoundEntity {
@Valid
Entity entity;
}
class Entity {
@NotNull(groups=Group1.class)
String value1;
@NotNull(groups=Group2.class)
String value2;
}
class TestImpl {
void test(@Valid CompoundEntity compoundEntity)
}
Validating method test of class TestImpl for group CompoundGroup with a CompoundEntity comprising of an Entity with both value1 and value 2 set to null, one would expect the following:
- Validation be run for Group1
- A ConstraintViolation to be given for Entity::value1
- Validating halting after Group1 validation is complete because a constraint violation is given.
This behaviour is seen when validating said CompoundEntity directly, however the method validator does not bail if a group in the sequence raises a ConstraintViolation. See also attached test-case. I noticed in ValidatorImpl::validateParametersInContext (line 1170 of 5.2.4-Final) only numberOfFailingConstraints is checked, rather than a construction similar to the validateInContext method that checks the amount of failing constraints of the context. This causes any constraint violations resulting from the validateCascadedConstraints call to be ignored. If I can find some time this evening I will provide a pull request with the suggested fix. |