Alex Fedotov (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%...
) *created* an issue
Hibernate Validator (
https://hibernate.atlassian.net/browse/HV?atlOrigin=eyJpIjoiM2RkOGMzNDlmM...
) / Bug (
https://hibernate.atlassian.net/browse/HV-1791?atlOrigin=eyJpIjoiM2RkOGMz...
) HV-1791 (
https://hibernate.atlassian.net/browse/HV-1791?atlOrigin=eyJpIjoiM2RkOGMz...
) Cascading validation on list items is not invoked (
https://hibernate.atlassian.net/browse/HV-1791?atlOrigin=eyJpIjoiM2RkOGMz...
)
Issue Type: Bug Affects Versions: 6.1.5.Final Assignee: Unassigned Components: engine
Created: 17/Jul/2020 09:26 AM Priority: Major Reporter: Alex Fedotov (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%...
)
Trying to validate a POJO with nested collection that requires item validation
class TestTopLevel
{ public List<@Valid TestDetails> data = new ArrayList<>(); }
class TestDetails
{ @NotEmpty public String large = ""; }
TestTopLevel topLevelValue = new TestTopLevel();
TestDetails details = new TestDetails();
topLevelValue.data = new ArrayList<>();
topLevelValue.data.add(details);
Both validateProperty and validateValue fail to validate the list items.
violations = validator.validateProperty(topLevelValue, "data");
violations = validator.validateValue(TestTopLevel.class, "data",
topLevelValue);
It appears that the issue is in the validationContext.appliesTo( metaConstraint ) call.
metaConstraint is correctly pointing to the "large" property of the item in the
list when it gets there.
However "validatedProperty" value at this point is "data" from the top
level class.
@Override
public boolean appliesTo(MetaConstraint<?> metaConstraint)
{ return Objects.equals( validatedProperty, getPropertyName( metaConstraint.getLocation()
) ); }
private boolean validateMetaConstraint(BaseBeanValidationContext<?>
validationContext, ValueContext<?, Object> valueContext, Object parent,
MetaConstraint<?> metaConstraint) {
BeanValueContext.ValueState<Object> originalValueState =
valueContext.getCurrentValueState();
valueContext.appendNode( metaConstraint.getLocation() );
boolean success = true;
if ( isValidationRequired( validationContext, valueContext, metaConstraint ) ) {
The equals check fails and the validation of the item is skipped because
isValidationRequired returns false.
(
https://hibernate.atlassian.net/browse/HV-1791#add-comment?atlOrigin=eyJp...
) Add Comment (
https://hibernate.atlassian.net/browse/HV-1791#add-comment?atlOrigin=eyJp...
)
Get Jira notifications on your phone! Download the Jira Cloud app for Android (
https://play.google.com/store/apps/details?id=com.atlassian.android.jira....
) or iOS (
https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=Em...
) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100133- sha1:d093d11 )