37
37
import javax .validation .valueextraction .ValueExtractor ;
38
38
39
39
import org .hibernate .validator .internal .engine .ValidationContext .ValidationContextBuilder ;
40
+ import org .hibernate .validator .internal .engine .ValueContext .ValueState ;
40
41
import org .hibernate .validator .internal .engine .constraintvalidation .ConstraintValidatorManager ;
41
42
import org .hibernate .validator .internal .engine .groups .Group ;
42
43
import org .hibernate .validator .internal .engine .groups .GroupWithInheritance ;
43
44
import org .hibernate .validator .internal .engine .groups .Sequence ;
44
45
import org .hibernate .validator .internal .engine .groups .ValidationOrder ;
45
46
import org .hibernate .validator .internal .engine .groups .ValidationOrderGenerator ;
46
47
import org .hibernate .validator .internal .engine .path .NodeImpl ;
47
- import org .hibernate .validator .internal .engine .path .PathImpl ;
48
+ import org .hibernate .validator .internal .engine .path .PathBuilder ;
48
49
import org .hibernate .validator .internal .engine .resolver .CachingTraversableResolverForSingleValidation ;
49
50
import org .hibernate .validator .internal .engine .valueextraction .ValueExtractorDescriptor ;
50
51
import org .hibernate .validator .internal .engine .valueextraction .ValueExtractorHelper ;
@@ -177,7 +178,7 @@ public final <T> Set<ConstraintViolation<T>> validate(T object, Class<?>... grou
177
178
parameterNameProvider ,
178
179
object ,
179
180
validationContext .getRootBeanMetaData (),
180
- PathImpl .createRootPath ()
181
+ PathBuilder .createRootPath ()
181
182
);
182
183
183
184
return validateInContext ( validationContext , valueContext , validationOrder );
@@ -195,7 +196,7 @@ public final <T> Set<ConstraintViolation<T>> validateProperty(T object, String p
195
196
return Collections .emptySet ();
196
197
}
197
198
198
- PathImpl propertyPath = PathImpl .createPathFromString ( propertyName );
199
+ PathBuilder propertyPath = PathBuilder .createPathFromString ( propertyName );
199
200
ValueContext <?, Object > valueContext = getValueContextForPropertyValidation ( validationContext , propertyPath );
200
201
201
202
if ( valueContext .getCurrentBean () == null ) {
@@ -224,7 +225,7 @@ public final <T> Set<ConstraintViolation<T>> validateValue(Class<T> beanType, St
224
225
return validateValueInContext (
225
226
validationContext ,
226
227
value ,
227
- PathImpl .createPathFromString ( propertyName ),
228
+ PathBuilder .createPathFromString ( propertyName ),
228
229
validationOrder
229
230
);
230
231
}
@@ -551,11 +552,11 @@ private boolean validateMetaConstraint(ValidationContext<?> validationContext, V
551
552
552
553
success = metaConstraint .validateConstraint ( validationContext , valueContext );
553
554
554
- validationContext .markConstraintProcessed ( valueContext .getCurrentBean (), valueContext .getPropertyPath (), metaConstraint );
555
+ validationContext .markConstraintProcessed ( valueContext .getCurrentBean (), valueContext .getPropertyPath (). build () , metaConstraint );
555
556
}
556
557
557
558
// reset the value context to the state before this call
558
- valueContext .resetValueState ( originalValueState );
559
+ valueContext .resetValueState ( originalValueState , true );
559
560
560
561
return success ;
561
562
}
@@ -600,13 +601,13 @@ private void validateCascadedConstraints(ValidationContext<?> validationContext,
600
601
}
601
602
602
603
// reset the value context
603
- valueContext .resetValueState ( originalValueState );
604
+ valueContext .resetValueState ( originalValueState , true );
604
605
}
605
606
}
606
607
607
608
private void validateCascadedAnnotatedObjectForCurrentGroup (Object value , ValidationContext <?> validationContext , ValueContext <?, Object > valueContext ,
608
609
CascadingMetaData cascadingMetaData ) {
609
- if ( validationContext .isBeanAlreadyValidated ( value , valueContext .getCurrentGroup (), valueContext .getPropertyPath () ) ||
610
+ if ( validationContext .isBeanAlreadyValidated ( value , valueContext .getCurrentGroup (), valueContext .getPropertyPath (). build () ) ||
610
611
shouldFailFast ( validationContext ) ) {
611
612
return ;
612
613
}
@@ -682,7 +683,7 @@ public void keyedValue(String nodeName, Object key, Object value) {
682
683
683
684
private void doValidate (Object value , String nodeName ) {
684
685
if ( value == null ||
685
- validationContext .isBeanAlreadyValidated ( value , valueContext .getCurrentGroup (), valueContext .getPropertyPath () ) ||
686
+ validationContext .isBeanAlreadyValidated ( value , valueContext .getCurrentGroup (), valueContext .getPropertyPath (). build () ) ||
686
687
shouldFailFast ( validationContext ) ) {
687
688
return ;
688
689
}
@@ -713,11 +714,15 @@ private void doValidate(Object value, String nodeName) {
713
714
cascadedValueContext .setTypeParameter ( cascadingMetaData .getDeclaredContainerClass (), cascadingMetaData .getDeclaredTypeParameter () );
714
715
}
715
716
717
+ ValueState <Object > valueState = cascadedTypeArgumentValueContext .getCurrentValueState ();
718
+
716
719
if ( nodeName != null ) {
717
720
cascadedTypeArgumentValueContext .appendTypeParameterNode ( nodeName );
718
721
}
719
722
720
723
validateCascadedContainerElementsInContext ( value , validationContext , cascadedTypeArgumentValueContext , cascadingMetaData , validationOrder );
724
+
725
+ cascadedTypeArgumentValueContext .resetValueState ( valueState , nodeName != null );
721
726
}
722
727
}
723
728
}
@@ -780,7 +785,7 @@ private ValueContext<?, Object> buildNewLocalExecutionContext(ValueContext<?, ?>
780
785
return newValueContext ;
781
786
}
782
787
783
- private <T > Set <ConstraintViolation <T >> validateValueInContext (ValidationContext <T > validationContext , Object value , PathImpl propertyPath ,
788
+ private <T > Set <ConstraintViolation <T >> validateValueInContext (ValidationContext <T > validationContext , Object value , PathBuilder propertyPath ,
784
789
ValidationOrder validationOrder ) {
785
790
ValueContext <?, Object > valueContext = getValueContextForValueValidation ( validationContext , propertyPath );
786
791
valueContext .setCurrentValidatedValue ( value );
@@ -868,7 +873,7 @@ private <T> void validateParametersInContext(ValidationContext<T> validationCont
868
873
parameterNameProvider ,
869
874
parameterValues ,
870
875
executableMetaData .getValidatableParametersMetaData (),
871
- PathImpl .createPathForExecutable ( executableMetaData )
876
+ PathBuilder .createPathForExecutable ( executableMetaData )
872
877
);
873
878
874
879
groupIterator = validationOrder .getGroupIterator ();
@@ -1002,7 +1007,7 @@ private <T> ValueContext<T, Object> getExecutableValueContext(T object, Executab
1002
1007
parameterNameProvider ,
1003
1008
object ,
1004
1009
validatable ,
1005
- PathImpl .createPathForExecutable ( executableMetaData )
1010
+ PathBuilder .createPathForExecutable ( executableMetaData )
1006
1011
);
1007
1012
}
1008
1013
else {
@@ -1011,7 +1016,7 @@ private <T> ValueContext<T, Object> getExecutableValueContext(T object, Executab
1011
1016
parameterNameProvider ,
1012
1017
(Class <T >) null , //the type is not required in this case (only for cascaded validation)
1013
1018
validatable ,
1014
- PathImpl .createPathForExecutable ( executableMetaData )
1019
+ PathBuilder .createPathForExecutable ( executableMetaData )
1015
1020
);
1016
1021
}
1017
1022
@@ -1054,7 +1059,7 @@ private <V, T> void validateReturnValueInContext(ValidationContext<T> validation
1054
1059
parameterNameProvider ,
1055
1060
value ,
1056
1061
executableMetaData .getReturnValueMetaData (),
1057
- PathImpl .createPathForExecutable ( executableMetaData )
1062
+ PathBuilder .createPathForExecutable ( executableMetaData )
1058
1063
);
1059
1064
1060
1065
groupIterator = validationOrder .getGroupIterator ();
@@ -1159,7 +1164,7 @@ private <T> void validateReturnValueForSingleGroup(ValidationContext<T> validati
1159
1164
* @return Returns an instance of {@code ValueContext} which describes the local validation context associated to
1160
1165
* the given property path.
1161
1166
*/
1162
- private <V > ValueContext <?, V > getValueContextForPropertyValidation (ValidationContext <?> validationContext , PathImpl propertyPath ) {
1167
+ private <V > ValueContext <?, V > getValueContextForPropertyValidation (ValidationContext <?> validationContext , PathBuilder propertyPath ) {
1163
1168
Class <?> clazz = validationContext .getRootBeanClass ();
1164
1169
BeanMetaData <?> beanMetaData = validationContext .getRootBeanMetaData ();
1165
1170
Object value = validationContext .getRootBean ();
@@ -1237,7 +1242,7 @@ else if ( propertyPathNode.getKey() != null ) {
1237
1242
* the given property path.
1238
1243
*/
1239
1244
private <V > ValueContext <?, V > getValueContextForValueValidation (ValidationContext <?> validationContext ,
1240
- PathImpl propertyPath ) {
1245
+ PathBuilder propertyPath ) {
1241
1246
Class <?> clazz = validationContext .getRootBeanClass ();
1242
1247
BeanMetaData <?> beanMetaData = null ;
1243
1248
PropertyMetaData propertyMetaData = null ;
@@ -1298,7 +1303,7 @@ private boolean isValidationRequired(ValidationContext<?> validationContext,
1298
1303
}
1299
1304
if ( validationContext .hasMetaConstraintBeenProcessed (
1300
1305
valueContext .getCurrentBean (),
1301
- valueContext .getPropertyPath (),
1306
+ valueContext .getPropertyPath (). build () ,
1302
1307
metaConstraint
1303
1308
) ) {
1304
1309
return false ;
@@ -1315,7 +1320,7 @@ private boolean isValidationRequired(ValidationContext<?> validationContext,
1315
1320
);
1316
1321
}
1317
1322
1318
- private boolean isReachable (ValidationContext <?> validationContext , Object traversableObject , PathImpl path , ElementType type ) {
1323
+ private boolean isReachable (ValidationContext <?> validationContext , Object traversableObject , PathBuilder path , ElementType type ) {
1319
1324
if ( needToCallTraversableResolver ( path , type ) ) {
1320
1325
return true ;
1321
1326
}
@@ -1335,7 +1340,7 @@ private boolean isReachable(ValidationContext<?> validationContext, Object trave
1335
1340
}
1336
1341
}
1337
1342
1338
- private boolean needToCallTraversableResolver (PathImpl path , ElementType type ) {
1343
+ private boolean needToCallTraversableResolver (PathBuilder path , ElementType type ) {
1339
1344
// as the TraversableResolver interface is designed right now it does not make sense to call it when
1340
1345
// there is no traversable object hosting the property to be accessed. For this reason we don't call the resolver
1341
1346
// for class level constraints (ElementType.TYPE) or top level method parameters or return values.
@@ -1346,7 +1351,7 @@ private boolean needToCallTraversableResolver(PathImpl path, ElementType type) {
1346
1351
|| isReturnValueValidation ( path );
1347
1352
}
1348
1353
1349
- private boolean isCascadeRequired (ValidationContext <?> validationContext , Object traversableObject , PathImpl path , ElementType type ) {
1354
+ private boolean isCascadeRequired (ValidationContext <?> validationContext , Object traversableObject , PathBuilder path , ElementType type ) {
1350
1355
if ( needToCallTraversableResolver ( path , type ) ) {
1351
1356
return true ;
1352
1357
}
@@ -1375,15 +1380,15 @@ private boolean isClassLevelConstraint(ElementType type) {
1375
1380
return ElementType .TYPE .equals ( type );
1376
1381
}
1377
1382
1378
- private boolean isCrossParameterValidation (PathImpl path ) {
1383
+ private boolean isCrossParameterValidation (PathBuilder path ) {
1379
1384
return path .getLeafNode ().getKind () == ElementKind .CROSS_PARAMETER ;
1380
1385
}
1381
1386
1382
- private boolean isParameterValidation (PathImpl path ) {
1387
+ private boolean isParameterValidation (PathBuilder path ) {
1383
1388
return path .getLeafNode ().getKind () == ElementKind .PARAMETER ;
1384
1389
}
1385
1390
1386
- private boolean isReturnValueValidation (PathImpl path ) {
1391
+ private boolean isReturnValueValidation (PathBuilder path ) {
1387
1392
return path .getLeafNode ().getKind () == ElementKind .RETURN_VALUE ;
1388
1393
}
1389
1394
0 commit comments