quarkusio/quarkus · error · IllegalArgumentException
Page index must be >= 0 :
Error message
Page index must be >= 0 :
What it means
Panache's Page represents a pagination request (index + size). The constructor validates that the page index is non-negative; a negative index is meaningless in pagination, so it throws IllegalArgumentException immediately rather than producing an invalid query later.
Source
Thrown at extensions/panache/panache-common/runtime/src/main/java/io/quarkus/panache/common/Page.java:53
* @throws IllegalArgumentException if the page size is less than or equal to 0
* @see #ofSize(int)
*/
public Page(int size) {
this(0, size);
}
/**
* Builds a page of the given index and size.
*
* @param index the page index (0-based)
* @param size the page size
* @throws IllegalArgumentException if the page index is less than 0
* @throws IllegalArgumentException if the page size is less than or equal to 0
* @see #of(int, int)
*/
public Page(int index, int size) {
if (index < 0)
throw new IllegalArgumentException("Page index must be >= 0 : " + index);
if (size <= 0)
throw new IllegalArgumentException("Page size must be > 0 : " + size);
this.index = index;
this.size = size;
}
/**
* Builds a page of the given index and size.
*
* @param index the page index (0-based)
* @param size the page size
* @throws IllegalArgumentException if the page index is less than 0
* @throws IllegalArgumentException if the page size is less than or equal to 0
*/
public static Page of(int index, int size) {
return new Page(index, size);
}
View on GitHub (pinned to e1c734241f)
Solutions
- Validate/clamp the page index before constructing: Math.max(0, pageIndex).
- Return HTTP 400 for negative page parameters instead of letting them reach Panache.
- Use Page.of(index, size) with sanitized values.
Example fix
// before
Page p = Page.of(Integer.parseInt(request.getParam("page")), 20);
// after
int idx = Math.max(0, Integer.parseInt(request.getParam("page")));
Page p = Page.of(idx, 20); Defensive patterns
Strategy: validation
Validate before calling
int idx = /* user input */;
if (idx < 0) throw new BadRequestException("page index must be >= 0");
Page p = Page.of(idx, size); Type guard
Page safePage(Integer index, int size) {
return Page.of(index == null ? 0 : Math.max(0, index), size);
} Try / catch
try {
Page p = Page.of(index, size);
} catch (IllegalArgumentException e) {
throw new BadRequestException("Invalid page index: " + e.getMessage());
} Prevention
- Clamp client page numbers with Math.max(0, index)
- Never pass raw query params into Page/Page.of
- Default missing page parameters to 0
When it happens
Trigger: Calling new Page(-1, 10), Page.of(-1, 10), or chaining pagination APIs (page(int), page(Page)) that construct a Page with a negative index — often from unvalidated user input like ?page=-1.
Common situations: Passing a request query parameter straight into page() without validation; computing index as currentPage-1 when currentPage is 0; arithmetic underflow from offset math.
Related errors
- Limiting to 0 values is not supported
- Limiting to 0 values is not supported
- Limiting to 0 values is not supported
- Page size must be > 0 :
- Start index must be >= 0:
AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05).
Data as JSON: /api/errors/67b228b6f071be13.
Report an issue: GitHub.