DATAJPA-585 - Fixed potential NullPointerException in QueryDslJpaRepository.

findAll(Predicate, Pageable) now treats null Pageable instances correctly.
This commit is contained in:
Oliver Gierke
2015-10-06 07:34:12 +02:00
parent cfc3d99e62
commit 6c2b80a79a
2 changed files with 10 additions and 1 deletions

View File

@@ -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);
}

View File

@@ -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));
}
}