Skip to content

Commit 4e9f7a6

Browse files
committed
Fix #658 : Pager not working properly
Since the removal of "X-Total-Pages" and "X-Total" headers, all paginations use the kaminari counter. In this mode, kaminari counter is reset to -1 during the call of the last page. This part is correct. Then when we call the `current()` method of the pager to get the current page. This method call the same `page` method than the `next` method. In this method the pager check if there is element before checking if we call for the current page. It throws NoSuchElementException erroneously. To fix, I change the check sequence. First I check ifthe user call the current page. If so, we return the corresponding items. If not we check if there is such elements and call the API.
1 parent db8f925 commit 4e9f7a6

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/main/java/org/gitlab4j/api/Pager.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -306,12 +306,6 @@ public List<T> current() throws GitLabApiException {
306306
*/
307307
public List<T> page(int pageNumber) {
308308

309-
if (pageNumber > totalPages && pageNumber > kaminariNextPage) {
310-
throw new NoSuchElementException();
311-
} else if (pageNumber < 1) {
312-
throw new NoSuchElementException();
313-
}
314-
315309
if (currentPage == 0 && pageNumber == 1) {
316310
currentPage = 1;
317311
return (currentItems);
@@ -321,6 +315,12 @@ public List<T> page(int pageNumber) {
321315
return (currentItems);
322316
}
323317

318+
if (pageNumber > totalPages && pageNumber > kaminariNextPage) {
319+
throw new NoSuchElementException();
320+
} else if (pageNumber < 1) {
321+
throw new NoSuchElementException();
322+
}
323+
324324
try {
325325

326326
setPageParam(pageNumber);

0 commit comments

Comments
 (0)