[hibernate-issues] [JIRA] (HV-1791) Cascading validation on list items is not invoked

Alex Fedotov (JIRA) jira at hibernate.atlassian.net
Fri Jul 17 12:26:16 EDT 2020


Alex Fedotov ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%3Aa5525d69-bcad-4aa8-a516-f3018c8669a2 ) *created* an issue

Hibernate Validator ( https://hibernate.atlassian.net/browse/HV?atlOrigin=eyJpIjoiM2RkOGMzNDlmMzM4NGNjNDk2MzE2ZGIxZGU2YzJlOGUiLCJwIjoiaiJ9 ) / Bug ( https://hibernate.atlassian.net/browse/HV-1791?atlOrigin=eyJpIjoiM2RkOGMzNDlmMzM4NGNjNDk2MzE2ZGIxZGU2YzJlOGUiLCJwIjoiaiJ9 ) HV-1791 ( https://hibernate.atlassian.net/browse/HV-1791?atlOrigin=eyJpIjoiM2RkOGMzNDlmMzM4NGNjNDk2MzE2ZGIxZGU2YzJlOGUiLCJwIjoiaiJ9 ) Cascading validation on list items is not invoked ( https://hibernate.atlassian.net/browse/HV-1791?atlOrigin=eyJpIjoiM2RkOGMzNDlmMzM4NGNjNDk2MzE2ZGIxZGU2YzJlOGUiLCJwIjoiaiJ9 )

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%3Aa5525d69-bcad-4aa8-a516-f3018c8669a2 )

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=eyJpIjoiM2RkOGMzNDlmMzM4NGNjNDk2MzE2ZGIxZGU2YzJlOGUiLCJwIjoiaiJ9 ) Add Comment ( https://hibernate.atlassian.net/browse/HV-1791#add-comment?atlOrigin=eyJpIjoiM2RkOGMzNDlmMzM4NGNjNDk2MzE2ZGIxZGU2YzJlOGUiLCJwIjoiaiJ9 )

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.core&referrer=utm_source%3DNotificationLink%26utm_medium%3DEmail ) or iOS ( https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=EmailNotificationLink&mt=8 ) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100133- sha1:d093d11 )
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/hibernate-issues/attachments/20200717/88a7276f/attachment.html 


More information about the hibernate-issues mailing list