Skip to content

Commit 6c2b80a

Browse files
committed
DATAJPA-585 - Fixed potential NullPointerException in QueryDslJpaRepository.
findAll(Predicate, Pageable) now treats null Pageable instances correctly.
1 parent cfc3d99 commit 6c2b80a

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/main/java/org/springframework/data/jpa/repository/support/QueryDslJpaRepository.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ public Page<T> findAll(Predicate predicate, Pageable pageable) {
139139
JPQLQuery query = querydsl.applyPagination(pageable, createQuery(predicate));
140140

141141
Long total = countQuery.count();
142-
List<T> content = total > pageable.getOffset() ? query.list(path) : Collections.<T> emptyList();
142+
List<T> content = pageable == null || total > pageable.getOffset() ? query.list(path) : Collections.<T> emptyList();
143143

144144
return new PageImpl<T>(content, pageable, total);
145145
}

src/test/java/org/springframework/data/jpa/repository/support/QueryDslJpaRepositoryTests.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.junit.runner.RunWith;
3030
import org.springframework.data.domain.Page;
3131
import org.springframework.data.domain.PageRequest;
32+
import org.springframework.data.domain.Pageable;
3233
import org.springframework.data.domain.Sort;
3334
import org.springframework.data.domain.Sort.Direction;
3435
import org.springframework.data.domain.Sort.Order;
@@ -350,4 +351,12 @@ public void shouldSupportFindAllWithPredicateAndSort() {
350351
assertThat(users.get(2).getFirstname(), is(oliver.getFirstname()));
351352
assertThat(users, hasItems(carter, dave, oliver));
352353
}
354+
355+
/**
356+
* @see DATAJPA-585
357+
*/
358+
@Test
359+
public void worksWithNullPageable() {
360+
assertThat(repository.findAll(user.dateOfBirth.isNull(), (Pageable) null).getContent(), hasSize(3));
361+
}
353362
}

0 commit comments

Comments
 (0)