Skip to content

Commit 807a53d

Browse files
marko-bekhtagsmet
authored andcommitted
HV-1692 Change when beans are marked as processed
- in case of redefined group sequences only the last group was marked as processed while all other groups were ignored. Marking bean as processed in the loop allows to catch all the groups in the sequence
1 parent 4d5e327 commit 807a53d

File tree

2 files changed

+68
-2
lines changed

2 files changed

+68
-2
lines changed

engine/src/main/java/org/hibernate/validator/internal/engine/ValidatorImpl.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,9 @@ private <U> void validateConstraintsForDefaultGroup(BaseBeanValidationContext<?>
452452
validationSuccessful = validateConstraintsForSingleDefaultGroupElement( validationContext, valueContext, validatedInterfaces, clazz,
453453
metaConstraints, defaultSequenceMember );
454454
}
455+
456+
validationContext.markCurrentBeanAsProcessed( valueContext );
457+
455458
if ( !validationSuccessful ) {
456459
break;
457460
}
@@ -463,10 +466,9 @@ private <U> void validateConstraintsForDefaultGroup(BaseBeanValidationContext<?>
463466
Set<MetaConstraint<?>> metaConstraints = hostingBeanMetaData.getDirectMetaConstraints();
464467
validateConstraintsForSingleDefaultGroupElement( validationContext, valueContext, validatedInterfaces, clazz, metaConstraints,
465468
Group.DEFAULT_GROUP );
469+
validationContext.markCurrentBeanAsProcessed( valueContext );
466470
}
467471

468-
validationContext.markCurrentBeanAsProcessed( valueContext );
469-
470472
// all constraints in the hierarchy has been validated, stop validation.
471473
if ( defaultGroupSequenceIsRedefined ) {
472474
break;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* Hibernate Validator, declare and validate application constraints
3+
*
4+
* License: Apache License, Version 2.0
5+
* See the license.txt file in the root directory or <http://www.apache.org/licenses/LICENSE-2.0>.
6+
*/
7+
package org.hibernate.validator.test.internal.engine.groups.sequence;
8+
9+
import java.util.Set;
10+
11+
import javax.validation.ConstraintViolation;
12+
import javax.validation.GroupSequence;
13+
import javax.validation.Valid;
14+
import javax.validation.Validator;
15+
16+
import org.hibernate.validator.testutil.TestForIssue;
17+
import org.hibernate.validator.testutils.ValidatorUtil;
18+
19+
import org.testng.Assert;
20+
import org.testng.annotations.Test;
21+
22+
@TestForIssue(jiraKey = "HV-1692")
23+
public class SequenceOnObjectsWithCycles {
24+
25+
@Test
26+
public void groupSequenceOfGroupSequences() {
27+
Validator validator = ValidatorUtil.getValidator();
28+
29+
YourAnnotatedBean yourEntity1 = new YourAnnotatedBean();
30+
AnotherBean anotherBean = new AnotherBean();
31+
anotherBean.setYourAnnotatedBean( yourEntity1 );
32+
yourEntity1.setBean( anotherBean );
33+
34+
Set<ConstraintViolation<YourAnnotatedBean>> constraintViolations = validator.validate( yourEntity1 );
35+
Assert.assertEquals( 0, constraintViolations.size() );
36+
37+
}
38+
39+
@GroupSequence({ AnotherBean.class, Magic.class })
40+
public class AnotherBean {
41+
42+
@Valid
43+
private YourAnnotatedBean yourAnnotatedBean;
44+
45+
46+
public void setYourAnnotatedBean(YourAnnotatedBean yourAnnotatedBean) {
47+
this.yourAnnotatedBean = yourAnnotatedBean;
48+
}
49+
}
50+
51+
@GroupSequence({ YourAnnotatedBean.class, Magic.class })
52+
public class YourAnnotatedBean {
53+
54+
@Valid
55+
private AnotherBean bean;
56+
57+
public void setBean(AnotherBean bean) {
58+
this.bean = bean;
59+
}
60+
}
61+
62+
public interface Magic {
63+
}
64+
}

0 commit comments

Comments
 (0)