Skip to content

Commit

Permalink
Fix stack overflow error
Browse files Browse the repository at this point in the history
  • Loading branch information
madurangasiriwardena committed Dec 3, 2024
1 parent a9b0d4f commit 51438ce
Showing 1 changed file with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,17 @@ public static Map<String, String> buildPaginationLinks(int limit, int currentOff

private static int calculateOffsetForPreviousLink(int offset, int limit, int total) {

if (limit <= 0) {
// If limit is 0 or negative, consider it as 0 and build the previous page.
return offset;
}

int newOffset = (offset - limit);
if (newOffset < total) {
return newOffset;
}

// If offset is greater than total, go back by the chunks of limit until a proper page is found.
return calculateOffsetForPreviousLink(newOffset, limit, total);
}

Expand Down

0 comments on commit 51438ce

Please sign in to comment.