{"record":{"id":"49652accef1ba39e","repo":"quarkusio/quarkus","slug":"page-size-must-be-0","errorCode":null,"errorMessage":"Page size must be > 0 : ","messagePattern":"Page size 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":55,"sourceCode":"     */\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\n    /**\n     * Builds a page of the given size.","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/extensions/panache/panache-common/runtime/src/main/java/io/quarkus/panache/common/Page.java#L37-L73","documentation":"Panache's Page constructor requires a strictly positive page size; a zero or negative size cannot describe a page of results, so the constructor throws IllegalArgumentException with the offending value.","triggerScenarios":"Calling new Page(0, 0), Page.of(0, -10), or building a page from an unvalidated user-provided/zero-defaulted size parameter.","commonSituations":"Client sends ?size=0; a config default of 0 for page size; integer parsing failures defaulting to 0; division-based size computation producing 0.","solutions":["Validate/clamp the size before constructing: Math.max(1, pageSize).","Treat size<=0 from clients as an HTTP 400 Bad Request.","Apply a server-side default page size when the client value is absent or non-positive."],"exampleFix":"// before\nPage p = Page.of(0, config.pageSize()); // config.pageSize() == 0\n// after\nPage p = Page.of(0, Math.max(1, config.pageSize()));","handlingStrategy":"validation","validationCode":"int sz = /* user input */;\nif (sz <= 0) throw new BadRequestException(\"page size must be > 0\");\nPage p = Page.of(index, sz);","typeGuard":"Page safePage(int index, Integer size) {\n    return Page.of(index, size == null ? DEFAULT_SIZE : Math.max(1, size));\n}","tryCatchPattern":"try {\n    Page p = Page.of(index, size);\n} catch (IllegalArgumentException e) {\n    throw new BadRequestException(\"Invalid page size: \" + e.getMessage());\n}","preventionTips":["Clamp page size to at least 1 before constructing Page","Apply server-side default size when client value is 0/negative","Validate size in DTO/param binding"],"tags":["panache","pagination","illegal-argument"],"backgroundTag":"invalid-pagination-size","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}