DATAJPA-585 - Fixed potential NullPointerException in QueryDslJpaRepository.
findAll(Predicate, Pageable) now treats null Pageable instances correctly.
This commit is contained in:
@@ -139,7 +139,7 @@ public class QueryDslJpaRepository<T, ID extends Serializable> extends SimpleJpa
|
||||
JPQLQuery query = querydsl.applyPagination(pageable, createQuery(predicate));
|
||||
|
||||
Long total = countQuery.count();
|
||||
List<T> content = total > pageable.getOffset() ? query.list(path) : Collections.<T> emptyList();
|
||||
List<T> content = pageable == null || total > pageable.getOffset() ? query.list(path) : Collections.<T> emptyList();
|
||||
|
||||
return new PageImpl<T>(content, pageable, total);
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.domain.Sort.Direction;
|
||||
import org.springframework.data.domain.Sort.Order;
|
||||
@@ -350,4 +351,12 @@ public class QueryDslJpaRepositoryTests {
|
||||
assertThat(users.get(2).getFirstname(), is(oliver.getFirstname()));
|
||||
assertThat(users, hasItems(carter, dave, oliver));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATAJPA-585
|
||||
*/
|
||||
@Test
|
||||
public void worksWithNullPageable() {
|
||||
assertThat(repository.findAll(user.dateOfBirth.isNull(), (Pageable) null).getContent(), hasSize(3));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user