spring-projects / spring-data-commons

Spring Data Commons. Interfaces and code shared between the various datastore specific implementations.
https://spring.io/projects/spring-data
Apache License 2.0
770 stars 670 forks source link

Pageable fails when page size is 1 and 1 row returned by query [DATACMNS-1634] #2060

Open spring-projects-issues opened 4 years ago

spring-projects-issues commented 4 years ago

Branko opened DATACMNS-1634 and commented

When there is only one row to return from a query, and a page size is set to 1, an exception is thrown in org.springframework.data.repository.support.PageableExecutionUtils line 62. The exception is actually thrown as java.lang.NumberFormatException because a non-numeric string value (the actual result of the query) is attempted to be converted to Long, which of course leads to NumberFormatException. Perhaps, the condition in line 58 of PageableExecutionUtils should be changed from

if (pageable.isUnpaged() || pageable.getPageSize() > content.size()) {

 

to

 

if (pageable.isUnpaged() || pageable.getPageSize() >= content.size()) {

because this works correctly when page size is given as higher than the number of returned rows.

 


No further details from DATACMNS-1634

spring-projects-issues commented 4 years ago

Jens Schauder commented

I haven't looked into this at all but it sounds similar to DATAJPA-1544. If this is in deed the same issue fixing it in commons wouldn't work