Skip to content

Commit

Permalink
fix(datastore): guard against "Type must not be Null" (#2797)
Browse files Browse the repository at this point in the history
Fixes: #2774.
  • Loading branch information
meltsufin committed Apr 30, 2024
1 parent 65c528c commit 9a2ee15
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ && getDiscriminatorValue().equals(persistentEntity.getDiscriminatorValue())) {
private void addEntityToDiscriminationFamily() {
Class parentClass = getType().getSuperclass();
DatastorePersistentEntity parentEntity =
parentClass != Object.class
parentClass != null && parentClass != Object.class
? this.datastoreMappingContext.getPersistentEntity(parentClass)
: null;
if (parentEntity != null && parentEntity.getDiscriminationFieldName() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import java.io.Serializable;
import org.junit.jupiter.api.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.Transient;
import org.springframework.data.mapping.PersistentPropertyAccessor;
import org.springframework.data.mapping.SimplePropertyHandler;
import org.springframework.data.util.ClassTypeInformation;
import org.springframework.data.util.TypeInformation;
import org.springframework.expression.spel.SpelEvaluationException;

Expand Down Expand Up @@ -180,6 +180,13 @@ void testEntityMissingDiscriminationSuperclass() {
.hasMessageContaining("This class expects a discrimination field but none are designated");
}

@Test
void testInterfaceProperty() {
DatastorePersistentEntity<?> persistentEntity = new DatastoreMappingContext().getPersistentEntity(EntityWithInterface.class);
assertThat(persistentEntity).isNotNull();
assertThat(persistentEntity.getPersistentProperty("text")).isNotNull();
}

@Entity
@DiscriminatorField(field = "colA")
@DiscriminatorValue("a")
Expand Down Expand Up @@ -247,4 +254,10 @@ private static class EntityWithExpression {
private static class EntityWithNoId {
String id;
}

private static class EntityWithInterface {
@Id String id;

Serializable text;
}
}

0 comments on commit 9a2ee15

Please sign in to comment.