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

Unable to specify constraints at more than 1 nested parameter of a typed container

Description

I am attempting to build a nested constraint mapping for a container using the containerElementType method and I noticed that I am only able to create constraints at 1 nested parameter of a typed container.

Tracing through the code I think the hashmap put at line 137 of CascadableConstraintMappingContextImplBase is allowing only 1 nested constraint value to be kept because it is keying on index which is 1 in both cases.

1 containerElementContexts.put( index, containerElementContext );

I was able to reproduce the issue with a small modification to the canDeclareDeeplyNestedContainerElementConstraintsForFieldProgrammatically method of ProgrammaticContainerElementConstraintsForFieldTest that adds a size constraint to the list of fish. I noticed that if i flip the order i declare the constraints it affects which violation makes it through and which is thrown out.

Here is a test case to reproduce this issue. It leverages the FishTank type from ProgrammaticContainerElementConstraintsForFieldTest

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 @Test @TestForIssue(jiraKey = "HV-1614") public void canDeclareMultipleDeeplyNestedContainerElementConstraintsForFieldProgrammatically() { ConstraintMapping newMapping = config.createConstraintMapping(); newMapping .type( FishTank.class ) .property( "fishOfTheMonth", FIELD ) .containerElementType( 1 ) .constraint(new SizeDef().min( 3 ).message( "there must be at least {min} fish of the month" )) .containerElementType( 1, 0 ) .constraint( new NotNullDef() ); config.addMapping( newMapping ); Validator validator = config.buildValidatorFactory().getValidator(); Set<ConstraintViolation<FishTank>> violations = validator.validate( new FishTank() ); assertThat( violations ).containsOnlyViolations( violationOf( NotNull.class ).withMessage( "must not be null" ), violationOf( Size.class ).withMessage( "there must be at least 3 fish of the month" ) ); }

Environment

java 8 66
eclipse 4.6.1
windows 7

Status

Assignee

Marko Bekhta

Reporter

Nathan James Deckard

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

6.0.9.Final

Priority

Major