{"record":{"id":"67b228b6f071be13","repo":"quarkusio/quarkus","slug":"page-index-must-be-0","errorCode":null,"errorMessage":"Page index must be >= 0 : ","messagePattern":"Page index must be >= 0 : ","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"extensions/panache/panache-common/runtime/src/main/java/io/quarkus/panache/common/Page.java","lineNumber":53,"sourceCode":"     * @throws IllegalArgumentException if the page size is less than or equal to 0\n     * @see #ofSize(int)\n     */\n    public Page(int size) {\n        this(0, size);\n    }\n\n    /**\n     * Builds a page of the given index and size.\n     *\n     * @param index the page index (0-based)\n     * @param size the page size\n     * @throws IllegalArgumentException if the page index is less than 0\n     * @throws IllegalArgumentException if the page size is less than or equal to 0\n     * @see #of(int, int)\n     */\n    public Page(int index, int size) {\n        if (index < 0)\n            throw new IllegalArgumentException(\"Page index must be >= 0 : \" + index);\n        if (size <= 0)\n            throw new IllegalArgumentException(\"Page size must be > 0 : \" + size);\n        this.index = index;\n        this.size = size;\n    }\n\n    /**\n     * Builds a page of the given index and size.\n     *\n     * @param index the page index (0-based)\n     * @param size the page size\n     * @throws IllegalArgumentException if the page index is less than 0\n     * @throws IllegalArgumentException if the page size is less than or equal to 0\n     */\n    public static Page of(int index, int size) {\n        return new Page(index, size);\n    }\n","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/extensions/panache/panache-common/runtime/src/main/java/io/quarkus/panache/common/Page.java#L35-L71","documentation":"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.","triggerScenarios":"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.","commonSituations":"Passing a request query parameter straight into page() without validation; computing index as currentPage-1 when currentPage is 0; arithmetic underflow from offset math.","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."],"exampleFix":"// before\nPage p = Page.of(Integer.parseInt(request.getParam(\"page\")), 20);\n// after\nint idx = Math.max(0, Integer.parseInt(request.getParam(\"page\")));\nPage p = Page.of(idx, 20);","handlingStrategy":"validation","validationCode":"int idx = /* user input */;\nif (idx < 0) throw new BadRequestException(\"page index must be >= 0\");\nPage p = Page.of(idx, size);","typeGuard":"Page safePage(Integer index, int size) {\n    return Page.of(index == null ? 0 : Math.max(0, index), size);\n}","tryCatchPattern":"try {\n    Page p = Page.of(index, size);\n} catch (IllegalArgumentException e) {\n    throw new BadRequestException(\"Invalid page index: \" + e.getMessage());\n}","preventionTips":["Clamp client page numbers with Math.max(0, index)","Never pass raw query params into Page/Page.of","Default missing page parameters to 0"],"tags":["panache","pagination","illegal-argument"],"backgroundTag":"invalid-pagination-index","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}