DATAREST-1018 - Prevent NullPointerException in UriToEntityConverter.
In case PersistentEntities exposes a managed type whose raw type currently doesn't have a PersistentEntity registered, the constructor of UriToEntityConverter ran into a NullPointerException. We now explicitly check for null and skip those types. Filed DATAREST-1021 for further improvements in the 3.0 time frame.
This commit is contained in:
@@ -68,7 +68,7 @@ public class UriToEntityConverter implements ConditionalGenericConverter {
|
||||
Class<?> rawType = domainType.getType();
|
||||
PersistentEntity<?, ?> entity = entities.getPersistentEntity(rawType);
|
||||
|
||||
if (entity.hasIdProperty()) {
|
||||
if (entity != null && entity.hasIdProperty()) {
|
||||
convertiblePairs.add(new ConvertiblePair(URI.class, domainType.getType()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,6 +39,7 @@ import org.springframework.data.repository.core.RepositoryInformation;
|
||||
import org.springframework.data.repository.support.Repositories;
|
||||
import org.springframework.data.repository.support.RepositoryInvoker;
|
||||
import org.springframework.data.repository.support.RepositoryInvokerFactory;
|
||||
import org.springframework.data.util.ClassTypeInformation;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link UriToEntityConverter}.
|
||||
@@ -134,6 +135,19 @@ public class UriToEntityConverterUnitTests {
|
||||
new UriToEntityConverter(mock(PersistentEntities.class), invokerFactory, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATAREST-1018
|
||||
*/
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void doesNotRegisterTypeWithUnmanagedRawType() {
|
||||
|
||||
PersistentEntities entities = mock(PersistentEntities.class);
|
||||
doReturn(Arrays.asList(ClassTypeInformation.OBJECT)).when(entities).getManagedTypes();
|
||||
|
||||
new UriToEntityConverter(entities, invokerFactory, repositories);
|
||||
}
|
||||
|
||||
static class Entity {
|
||||
@Id String id;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user