{"record":{"id":"d00796508d260ac8","repo":"quarkusio/quarkus","slug":"cannot-call-a-page-related-method-call-page-page-d00796","errorCode":null,"errorMessage":"Cannot call a page related method, call page(Page) or page(int, int) to initiate pagination first","messagePattern":"Cannot call a page related method, call page\\(Page\\) or page\\(int, int\\) to initiate pagination first","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"extensions/panache/mongodb-panache-common/runtime/src/main/java/io/quarkus/mongodb/panache/common/runtime/CommonPanacheQueryImpl.java","lineNumber":131,"sourceCode":"        return page.index > 0;\n    }\n\n    public int pageCount() {\n        checkPagination();\n        long count = count();\n        if (count == 0)\n            return 1; // a single page of zero results\n        return (int) Math.ceil((double) count / (double) page.size);\n    }\n\n    public Page page() {\n        checkPagination();\n        return page;\n    }\n\n    private void checkPagination() {\n        if (page == null) {\n            throw new UnsupportedOperationException(\n                    \"Cannot call a page related method, \"\n                            + \"call page(Page) or page(int, int) to initiate pagination first\");\n        }\n        if (range != null) {\n            throw new UnsupportedOperationException(\"Cannot call a page related method in a ranged query, \" +\n                    \"call page(Page) or page(int, int) to initiate pagination first\");\n        }\n    }\n\n    public <T extends Entity> CommonPanacheQueryImpl<T> range(int startIndex, int lastIndex) {\n        this.range = Range.of(startIndex, lastIndex);\n        // reset the page to its default to be able to switch from page to range\n        this.page = null;\n        return (CommonPanacheQueryImpl<T>) this;\n    }\n\n    public <T extends Entity> CommonPanacheQueryImpl<T> withCollation(Collation collation) {\n        this.collation = collation;","sourceCodeStart":113,"sourceCodeEnd":149,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/extensions/panache/mongodb-panache-common/runtime/src/main/java/io/quarkus/mongodb/panache/common/runtime/CommonPanacheQueryImpl.java#L113-L149","documentation":"Page-related navigation methods (nextPage, previousPage, firstPage, lastPage, hasNextPage, hasPreviousPage) on a PanacheQuery require that pagination was explicitly initialized with page(Page) or page(int,int). If query.page() was never called and the internal page field is null, checkPagination() throws this UnsupportedOperationException.","triggerScenarios":"Calling any of nextPage(), previousPage(), firstPage(), lastPage(), hasNextPage(), hasPreviousPage() directly on a PanacheQuery created by find()/list()/findAll() without first calling page(size) or page(index,size).","commonSituations":"Developers assuming Panache queries are paginated by default; migrating code that previously called page() upstream and forgetting it after refactoring; reading pagination state before initiating pagination.","solutions":["Call page(int pageSize) or page(int pageIndex, int pageSize) on the query before any page-related method","Pass a Page object: query.page(Page.of(pageIndex, pageSize))","If you only need slicing without paging semantics, use range(startIndex, lastIndex) instead and avoid page methods"],"exampleFix":"// before\nPanacheQuery<Person> query = Person.find(\"status\", \"active\");\nboolean more = query.hasNextPage();\n\n// after\nPanacheQuery<Person> query = Person.find(\"status\", \"active\").page(1, 20);\nboolean more = query.hasNextPage();","handlingStrategy":"validation","validationCode":"if (query.page() == null) { // UnsupportedOperationException otherwise\n    query.page(1, 20);\n}","typeGuard":null,"tryCatchPattern":"try {\n    boolean more = query.hasNextPage();\n} catch (UnsupportedOperationException e) {\n    if (e.getMessage().contains(\"initiate pagination first\")) {\n        query.page(1, 20); // recover by initializing pagination\n    } else { throw e; }\n}","preventionTips":["Always call .page(pageIndex, pageSize) immediately after find()/findAll() when using queries","Wrap query creation in a helper/factory that guarantees pagination is initialized","Never call hasNextPage()/nextPage() on range()-based queries","Add unit tests for paginated repository methods so the failure surfaces in CI"],"tags":["mongodb","panache","pagination","unsupported-operation"],"backgroundTag":"pagination-not-initialized","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"}