Skip to content

Commit 1bb1e94

Browse files
committed
HV-1831 Make path fully modifiable
make it more of a builder Signed-off-by: marko-bekhta <[email protected]>
1 parent 13f69a9 commit 1bb1e94

34 files changed

+739
-320
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@
3838
import org.hibernate.validator.internal.engine.groups.Sequence;
3939
import org.hibernate.validator.internal.engine.groups.ValidationOrder;
4040
import org.hibernate.validator.internal.engine.groups.ValidationOrderGenerator;
41+
import org.hibernate.validator.internal.engine.path.ModifiableNode;
4142
import org.hibernate.validator.internal.engine.path.ModifiablePath;
42-
import org.hibernate.validator.internal.engine.path.NodeImpl;
4343
import org.hibernate.validator.internal.engine.resolver.TraversableResolvers;
4444
import org.hibernate.validator.internal.engine.validationcontext.BaseBeanValidationContext;
4545
import org.hibernate.validator.internal.engine.validationcontext.ExecutableValidationContext;
@@ -1195,7 +1195,7 @@ private <V> BeanValueContext<?, V> getValueContextForPropertyValidation(BaseBean
11951195

11961196
while ( propertyPathIter.hasNext() ) {
11971197
// cast is ok, since we are dealing with engine internal classes
1198-
NodeImpl propertyPathNode = (NodeImpl) propertyPathIter.next();
1198+
ModifiableNode propertyPathNode = (ModifiableNode) propertyPathIter.next();
11991199
propertyMetaData = getBeanPropertyMetaData( beanMetaData, propertyPathNode );
12001200

12011201
// if the property is not the leaf property, we set up the context for the next iteration
@@ -1214,7 +1214,7 @@ private <V> BeanValueContext<?, V> getValueContextForPropertyValidation(BaseBean
12141214
// if we are in the case of an iterable and we want to validate an element of this iterable, we have to get the
12151215
// element value
12161216
if ( propertyPathNode.isIterable() ) {
1217-
propertyPathNode = (NodeImpl) propertyPathIter.next();
1217+
propertyPathNode = (ModifiableNode) propertyPathIter.next();
12181218

12191219
if ( propertyPathNode.getIndex() != null ) {
12201220
value = ReflectionHelper.getIndexedValue( value, propertyPathNode.getIndex() );
@@ -1272,7 +1272,7 @@ private <V> BeanValueContext<?, V> getValueContextForValueValidation(Class<?> ro
12721272

12731273
while ( propertyPathIter.hasNext() ) {
12741274
// cast is ok, since we are dealing with engine internal classes
1275-
NodeImpl propertyPathNode = (NodeImpl) propertyPathIter.next();
1275+
ModifiableNode propertyPathNode = (ModifiableNode) propertyPathIter.next();
12761276
beanMetaData = beanMetaDataManager.getBeanMetaData( clazz );
12771277
propertyMetaData = getBeanPropertyMetaData( beanMetaData, propertyPathNode );
12781278

@@ -1281,7 +1281,7 @@ private <V> BeanValueContext<?, V> getValueContextForValueValidation(Class<?> ro
12811281
// if we are in the case of an iterable and we want to validate an element of this iterable, we have to get the
12821282
// type from the parameterized type
12831283
if ( propertyPathNode.isIterable() ) {
1284-
propertyPathNode = (NodeImpl) propertyPathIter.next();
1284+
propertyPathNode = (ModifiableNode) propertyPathIter.next();
12851285

12861286
clazz = ReflectionHelper.getClassFromType( ReflectionHelper.getCollectionElementType( propertyMetaData.getType() ) );
12871287
beanMetaData = beanMetaDataManager.getBeanMetaData( clazz );

engine/src/main/java/org/hibernate/validator/internal/engine/constraintvalidation/ConstraintValidatorContextImpl.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,10 @@ private void dropLeafNodeIfRequired() {
276276
if ( propertyPath.getLeafNode().getKind() == ElementKind.BEAN ) {
277277
propertyPath = ModifiablePath.createCopyWithoutLeafNode( propertyPath );
278278
}
279+
else {
280+
// if we haven't dropped the node, we should clean up "container-related" things:
281+
propertyPath.getLeafNode().reset();
282+
}
279283
}
280284
}
281285

engine/src/main/java/org/hibernate/validator/internal/engine/constraintvalidation/ConstraintViolationCreationContext.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
import java.util.Map;
1010

11+
import jakarta.validation.Path;
12+
1113
import org.hibernate.validator.internal.engine.path.ModifiablePath;
1214
import org.hibernate.validator.internal.util.stereotypes.Immutable;
1315
import org.hibernate.validator.messageinterpolation.ExpressionLanguageFeatureLevel;
@@ -23,7 +25,7 @@ public class ConstraintViolationCreationContext {
2325
private final String message;
2426
private final ExpressionLanguageFeatureLevel expressionLanguageFeatureLevel;
2527
private final boolean customViolation;
26-
private final ModifiablePath propertyPath;
28+
private final Path propertyPath;
2729
@Immutable
2830
private final Map<String, Object> messageParameters;
2931
@Immutable
@@ -40,7 +42,8 @@ public ConstraintViolationCreationContext(String message,
4042
this.message = message;
4143
this.expressionLanguageFeatureLevel = expressionLanguageFeatureLevel;
4244
this.customViolation = customViolation;
43-
this.propertyPath = property;
45+
// at this point we make a copy of the path to avoid side effects
46+
this.propertyPath = property.materialize();
4447
this.messageParameters = toImmutableMap( messageParameters );
4548
this.expressionVariables = toImmutableMap( expressionVariables );
4649
this.dynamicPayload = dynamicPayload;
@@ -58,7 +61,7 @@ public boolean isCustomViolation() {
5861
return customViolation;
5962
}
6063

61-
public final ModifiablePath getPath() {
64+
public final Path getPath() {
6265
return propertyPath;
6366
}
6467

0 commit comments

Comments
 (0)