DATACMNS-867 - ReflectionEntityInformation getId(Object) considers potential null values.
This commit is contained in:
committed by
Oliver Gierke
parent
6e0596694d
commit
bab5ddade9
@@ -76,7 +76,7 @@ public class ReflectionEntityInformation<T, ID extends Serializable> extends Abs
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public Optional<ID> getId(Object entity) {
|
||||
return entity == null ? null : Optional.of((ID) ReflectionUtils.getField(field, entity));
|
||||
return entity == null ? null : Optional.ofNullable((ID) ReflectionUtils.getField(field, entity));
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -57,6 +57,11 @@ public class ReflectionEntityInformationUnitTests {
|
||||
assertThat(information.isNew(primitiveId)).isFalse();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-867
|
||||
public void detectsNewStateForEntityWithNullId() {
|
||||
assertThat(new ReflectionEntityInformation<>(Sample.class).isNew(new Sample())).isTrue();
|
||||
}
|
||||
|
||||
private static <T> EntityInformation<T, Serializable> getEntityInformation(Class<T> type) {
|
||||
return new ReflectionEntityInformation<T, Serializable>(type, Id.class);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user