Fix potential NullPointerException in JpaQueryCreator.
With the commit for GH-2363, we introduced an unguarded call to ReturnedType.getTypeToRead(), which could return null under certain conditions. Unfortunately Spring Data JPA dod not contain a test case that triggered that scenario. This commit switches to ReturnedType.getReturnedType() which is non-nullable and lets us inspect the calls results for interfaces, which we need to create the JPA query properly. Fixes GH-2408
This commit is contained in:
@@ -176,7 +176,7 @@ public class JpaQueryCreator extends AbstractQueryCreator<CriteriaQuery<? extend
|
||||
selections.add(toExpressionRecursively(root, path, true).alias(property));
|
||||
}
|
||||
|
||||
Class<?> typeToRead = returnedType.getTypeToRead();
|
||||
Class<?> typeToRead = returnedType.getReturnedType();
|
||||
|
||||
query = typeToRead.isInterface()
|
||||
? query.multiselect(selections)
|
||||
|
||||
@@ -2621,6 +2621,14 @@ public class UserRepositoryTests {
|
||||
assertThat(repository.findAllDtoProjectedBy()).hasSize(4);
|
||||
}
|
||||
|
||||
@Test // GH-2408, GH-2363
|
||||
void readsDerivedInterfaceProjections() {
|
||||
|
||||
flushTestUsers();
|
||||
|
||||
assertThat(repository.findAllInterfaceProjectedBy()).hasSize(4);
|
||||
}
|
||||
|
||||
private Page<User> executeSpecWithSort(Sort sort) {
|
||||
|
||||
flushTestUsers();
|
||||
|
||||
@@ -614,6 +614,9 @@ public interface UserRepository
|
||||
// #2363
|
||||
List<NameOnlyDto> findAllDtoProjectedBy();
|
||||
|
||||
// GH-2408
|
||||
List<NameOnly> findAllInterfaceProjectedBy();
|
||||
|
||||
interface RolesAndFirstname {
|
||||
|
||||
String getFirstname();
|
||||
|
||||
Reference in New Issue
Block a user