From ae1af6cf40e359086cb29bb9ff58546b6b322d79 Mon Sep 17 00:00:00 2001 From: Greg Messner Date: Thu, 9 May 2019 12:54:58 -0700 Subject: [PATCH] Bug - Fixed issue with Pager when GitLab returns -1 for total-items. (#347) * Fixed issue caused by the GitLab server returning -1 for total items (#346). --- README.md | 4 ++-- pom.xml | 2 +- src/main/java/org/gitlab4j/api/Pager.java | 20 ++++++++++---------- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index d21dda57..b68588bc 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ To utilize GitLab4J™ API in your Java project, simply add the following de ```java dependencies { ... - compile group: 'org.gitlab4j', name: 'gitlab4j-api', version: '4.10.12' + compile group: 'org.gitlab4j', name: 'gitlab4j-api', version: '4.10.14' } ``` @@ -23,7 +23,7 @@ dependencies { org.gitlab4j gitlab4j-api - 4.10.12 + 4.10.14 ``` diff --git a/pom.xml b/pom.xml index 3a51c5ba..fe219237 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ org.gitlab4j gitlab4j-api jar - 4.10.13-SNAPSHOT + 4.10.14-SNAPSHOT GitLab4J-API - GitLab API Java Client GitLab4J-API (gitlab4j-api) provides a full featured Java client library for working with GitLab repositories and servers via the GitLab REST API. https://github.com/gitlab4j/gitlab4j-api diff --git a/src/main/java/org/gitlab4j/api/Pager.java b/src/main/java/org/gitlab4j/api/Pager.java index 8abf7d9a..a0c608e5 100644 --- a/src/main/java/org/gitlab4j/api/Pager.java +++ b/src/main/java/org/gitlab4j/api/Pager.java @@ -343,17 +343,17 @@ public class Pager implements Iterator>, Constants { */ public List all() throws GitLabApiException { - // Make sure that current page is 0, this will ensure the whole list is fetched - // regardless of what page the instance is currently on. - currentPage = 0; - List allItems = new ArrayList<>(totalItems); - - // Iterate through the pages and append each page of items to the list - while (hasNext()) { - allItems.addAll(next()); - } + // Make sure that current page is 0, this will ensure the whole list is fetched + // regardless of what page the instance is currently on. + currentPage = 0; + List allItems = new ArrayList<>(Math.max(totalItems, 0)); + + // Iterate through the pages and append each page of items to the list + while (hasNext()) { + allItems.addAll(next()); + } - return (allItems); + return (allItems); } /** -- GitLab