We're updating the issue view to help you get more done. 

Parameter validation does not stop when group in sequence has cascaded constraint violations.

Description

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:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 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.

Environment

None

Status

Assignee

Unassigned

Reporter

Jan-Willem Willebrands

Labels

None

Worked in

None

Feedback Requested

None

Feedback Requested By

None

backPortable

None

Community Help Wanted

None

Suitable for new contributors

None

Requires Release Note

None

backportDecision

None

backportReEvaluate

None

Components

Fix versions

Affects versions

5.2.4.Final

Priority

Major