Skip to content

Avoid obsolete null check for DefaultedPageable #2222

@j1myx

Description

@j1myx

I was looking for a way to make the endpoint return the data without paging, and since the documentation doesn't say anything about it, I started exploring the source code and I found something curious that I hope can tell me the reason why:

In the source code, precisely in the controller, it seems to provide a solution to my need, in which it is indicated that if the "pageable" property of the "pageable" object is null, all the data will be returned without paging. However, when exploring the "pageable" object, I am surprised that it will never be null, thus the endpoint will never return unpaged data.

Code snippet where the unnecessary condition is made:

Iterable<?> results = pageable.getPageable() != null
		? invoker.invokeFindAll(pageable.getPageable())
		: invoker.invokeFindAll(sort);

Full source code: https://github.com/spring-projects/spring-data-rest/blob/main/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/RepositoryEntityController.java
Line: 197

Fragmento de la clase DefaultedPageable donde se aprecia que la propiedad plegable nunca será nulo:

public final class DefaultedPageable {
      private final Pageable pageable;
      private final boolean isDefault;

      public DefaultedPageable(Pageable pageable, boolean isDefault) {
            Assert.notNull(pageable, "Pageable must not be null");

            this.pageable = pageable;
            this.isDefault = isDefault;
      }
}

Full source code: https://github.com/spring-projects/spring-data-rest/blob/main/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/support/DefaultedPageable.java

Please could you tell me the reason why you put that unnecessary condition? If it is a problem, please tell me so that I can collaborate in the correction and thus the data can be returned without pagination.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions