Skip to content

Commit 3b79cdd

Browse files
gsmetgunnarmorling
authored andcommitted
HV-1480 Only set the property value if required
Only property and container node exposes it to users.
1 parent 0e0d825 commit 3b79cdd

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ public final void setCurrentGroup(Class<?> currentGroup) {
192192
}
193193

194194
public final void setCurrentValidatedValue(V currentValue) {
195-
propertyPath.setLeafNodeValue( currentValue );
195+
propertyPath.setLeafNodeValueIfRequired( currentValue );
196196
this.currentValue = currentValue;
197197
}
198198

engine/src/main/java/org/hibernate/validator/internal/engine/path/PathImpl.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -222,13 +222,16 @@ public NodeImpl makeLeafNodeIterableAndSetMapKey(Object key) {
222222
return currentLeafNode;
223223
}
224224

225-
public NodeImpl setLeafNodeValue(Object value) {
226-
requiresWriteableNodeList();
225+
public NodeImpl setLeafNodeValueIfRequired(Object value) {
226+
// The value is only exposed for property and container element nodes
227+
if ( currentLeafNode.getKind() == ElementKind.PROPERTY || currentLeafNode.getKind() == ElementKind.CONTAINER_ELEMENT ) {
228+
requiresWriteableNodeList();
227229

228-
currentLeafNode = NodeImpl.setPropertyValue( currentLeafNode, value );
230+
currentLeafNode = NodeImpl.setPropertyValue( currentLeafNode, value );
229231

230-
nodeList.set( nodeList.size() - 1, currentLeafNode );
231-
hashCode = -1;
232+
nodeList.set( nodeList.size() - 1, currentLeafNode );
233+
hashCode = -1;
234+
}
232235
return currentLeafNode;
233236
}
234237

0 commit comments

Comments
 (0)