Skip to content

Commit 2e4e6ee

Browse files
committed
DATACMNS-929 - Fixed NullPointerException in PageableHandlerMethodArgumentResolver.
PageableHandlerMethodArgumentResolver.isFallbackPageable() now correctly guards against the fallback Pageable being null, a situation that's explicitly deemed valid in setFallbackPageable(…).
1 parent 0f76ffd commit 2e4e6ee

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

src/main/java/org/springframework/data/web/PageableHandlerMethodArgumentResolver.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2013-2015 the original author or authors.
2+
* Copyright 2013-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -95,12 +95,12 @@ public void setFallbackPageable(Pageable fallbackPageable) {
9595
/**
9696
* Returns whether the given {@link Pageable} is the fallback one.
9797
*
98-
* @param pageable
98+
* @param pageable can be {@literal null}.
9999
* @since 1.9
100100
* @return
101101
*/
102102
public boolean isFallbackPageable(Pageable pageable) {
103-
return this.fallbackPageable.equals(pageable);
103+
return fallbackPageable == null ? false : fallbackPageable.equals(pageable);
104104
}
105105

106106
/**

src/test/java/org/springframework/data/web/PageableHandlerMethodArgumentResolverUnitTests.java

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2013-2015 the original author or authors.
2+
* Copyright 2013-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -270,6 +270,19 @@ public void returnsCorrectPageSizeForOneIndexParameters() {
270270
assertThat(result.getPageSize(), is(10));
271271
}
272272

273+
/**
274+
* @see DATACMNS-929
275+
*/
276+
@Test
277+
public void detectsFallbackPageableIfNullOneIsConfigured() {
278+
279+
PageableHandlerMethodArgumentResolver resolver = getResolver();
280+
resolver.setFallbackPageable(null);
281+
282+
assertThat(resolver.isFallbackPageable(null), is(false));
283+
assertThat(resolver.isFallbackPageable(new PageRequest(0, 10)), is(false));
284+
}
285+
273286
@Override
274287
protected PageableHandlerMethodArgumentResolver getResolver() {
275288
PageableHandlerMethodArgumentResolver resolver = new PageableHandlerMethodArgumentResolver();

0 commit comments

Comments
 (0)