Skip to content

Commit f8129cb

Browse files
committed
HV-2127 Make root node constant
Signed-off-by: marko-bekhta <[email protected]>
1 parent 28dc796 commit f8129cb

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,13 @@ public class NodeImpl
4343

4444
private static final Log LOG = LoggerFactory.make( MethodHandles.lookup() );
4545

46+
static final NodeImpl ROOT_NODE;
47+
static {
48+
ROOT_NODE = NodeImpl.createBeanNode( null );
49+
ROOT_NODE.valueSet = true;
50+
ROOT_NODE.hashCode();
51+
}
52+
4653
private static final String INDEX_OPEN = "[";
4754
private static final String INDEX_CLOSE = "]";
4855
private static final String TYPE_PARAMETER_OPEN = "<";
@@ -553,7 +560,6 @@ else if ( !Arrays.equals( parameterTypes, other.parameterTypes ) ) {
553560
}
554561

555562
boolean isRootPath() {
556-
// .size() == 1 && nodeList.get( 0 ).getName() == null
557563
return parent == null && name == null;
558564
}
559565

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public final class PathImpl implements Path, Serializable {
6767
public static PathImpl createPathFromString(String propertyPath) {
6868
Contracts.assertNotNull( propertyPath, MESSAGES.propertyPathCannotBeNull() );
6969

70-
if ( propertyPath.length() == 0 ) {
70+
if ( propertyPath.isEmpty() ) {
7171
return createRootPath();
7272
}
7373

@@ -90,9 +90,7 @@ public static PathImpl createPathForExecutable(ExecutableMetaData executable) {
9090
}
9191

9292
public static PathImpl createRootPath() {
93-
PathImpl path = new PathImpl();
94-
path.addBeanNode();
95-
return path;
93+
return new PathImpl( NodeImpl.ROOT_NODE );
9694
}
9795

9896
public static PathImpl createCopy(PathImpl path) {

0 commit comments

Comments
 (0)