Skip to content

Commit e84a34a

Browse files
committed
Fixes NPE in PersistentPropertyPathExtension.equals.
Closes #1164
1 parent e8c933d commit e84a34a

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/PersistentPropertyPathExtensionUnitTests.java

+20
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,26 @@ void extendBy() {
200200
});
201201
}
202202

203+
@Test // GH--1164
204+
void equalsWorks() {
205+
206+
PersistentPropertyPathExtension root1 = extPath(entity);
207+
PersistentPropertyPathExtension root2 = extPath(entity);
208+
PersistentPropertyPathExtension path1 = extPath("withId");
209+
PersistentPropertyPathExtension path2 = extPath("withId");
210+
211+
assertSoftly(softly -> {
212+
213+
softly.assertThat(root1).describedAs("root is equal to self").isEqualTo(root1);
214+
softly.assertThat(root2).describedAs("root is equal to identical root").isEqualTo(root1);
215+
softly.assertThat(path1).describedAs("path is equal to self").isEqualTo(path1);
216+
softly.assertThat(path2).describedAs("path is equal to identical path").isEqualTo(path1);
217+
softly.assertThat(path1).describedAs("path is not equal to other path").isNotEqualTo(extPath("entityId"));
218+
softly.assertThat(root1).describedAs("root is not equal to path").isNotEqualTo(path1);
219+
softly.assertThat(path1).describedAs("path is not equal to root").isNotEqualTo(root1);
220+
});
221+
}
222+
203223
private PersistentPropertyPathExtension extPath(RelationalPersistentEntity<?> entity) {
204224
return new PersistentPropertyPathExtension(context, entity);
205225
}

spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/PersistentPropertyPathExtension.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ public boolean equals(Object o) {
442442
if (o == null || getClass() != o.getClass()) return false;
443443
PersistentPropertyPathExtension that = (PersistentPropertyPathExtension) o;
444444
return entity.equals(that.entity) &&
445-
path.equals(that.path);
445+
Objects.equals(path, that.path);
446446
}
447447

448448
@Override

0 commit comments

Comments
 (0)