DATAJPA-201 - Fixed NullPointerException for null Pageables.

The optimization for DATAJPA-124 introduced a NullPointerException being thrown if the Pageable instance handed to a paging query was null. Added a guard to handle this situation correctly. Unfortunately had to disable the test case for EclipseLink as the bug with HSQL still exists.
This commit is contained in:
Oliver Gierke
2012-04-27 18:44:48 +02:00
parent e8febae302
commit 5eaa686b9b
3 changed files with 15 additions and 1 deletions

View File

@@ -104,7 +104,8 @@ public abstract class JpaQueryExecution {
ParameterAccessor accessor = new ParametersParameterAccessor(parameters, values);
Pageable pageable = accessor.getPageable();
List<Object> content = total > pageable.getOffset() ? query.getResultList() : Collections.emptyList();
List<Object> content = pageable == null || total > pageable.getOffset() ? query.getResultList() : Collections
.emptyList();
return new PageImpl<Object>(content, pageable, total);
}

View File

@@ -35,4 +35,12 @@ public class EclipseLinkNamespaceUserRepositoryTests extends NamespaceUserReposi
public void findsAllByGivenIds() {
}
/**
* Ignored until https://bugs.eclipse.org/bugs/show_bug.cgi?id=349477 is resolved.
*/
@Override
public void allowsExecutingPageableMethodWithNullPageable() {
}
}

View File

@@ -818,6 +818,7 @@ public class UserRepositoryTests {
/**
* @see DATAJPA-201
*/
@Test
public void allowsExecutingPageableMethodWithNullPageable() {
flushTestUsers();
@@ -829,6 +830,10 @@ public class UserRepositoryTests {
Page<User> page = repository.findByFirstnameIn(null, "Oliver");
assertThat(page.getNumberOfElements(), is(1));
assertThat(page.getContent(), hasItem(firstUser));
page = repository.findAll((Pageable) null);
assertThat(page.getNumberOfElements(), is(3));
assertThat(page.getContent(), hasItems(firstUser, secondUser, thirdUser));
}
protected void flushTestUsers() {