DATACMNS-1581 - Tighten nullability constraints for Sort parameters in PageRequest factory methods.

We now explicitly rejects null values for the Sort parameters in the constructor of PageRequest to avoid the creation of invalid instances if the IDE validation of nullability constraints is not in use.
This commit is contained in:
Oliver Drotbohm
2019-09-25 13:29:30 +02:00
parent 74a26dd3fe
commit 221ad9353e
4 changed files with 27 additions and 5 deletions

View File

@@ -17,6 +17,7 @@ package org.springframework.data.domain;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
/**
* Basic Java Bean implementation of {@code Pageable}.
@@ -33,14 +34,16 @@ public class PageRequest extends AbstractPageRequest {
/**
* Creates a new {@link PageRequest} with sort parameters applied.
*
* @param page zero-based page index.
* @param size the size of the page to be returned.
* @param page zero-based page index, must not be negative.
* @param size the size of the page to be returned, must be greater than 0.
* @param sort must not be {@literal null}, use {@link Sort#unsorted()} instead.
*/
protected PageRequest(int page, int size, Sort sort) {
super(page, size);
Assert.notNull(sort, "Sort must not be null!");
this.sort = sort;
}