{"record":{"id":"dfce700128f18f59","repo":"quarkusio/quarkus","slug":"cannot-call-a-page-related-method-call-page-page-dfce70","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/reactive/runtime/CommonReactivePanacheQueryImpl.java","lineNumber":131,"sourceCode":"    }\n\n    public Uni<Integer> pageCount() {\n        checkPagination();\n        return count().map(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\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> CommonReactivePanacheQueryImpl<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 (CommonReactivePanacheQueryImpl<T>) this;\n    }\n\n    public <T extends Entity> CommonReactivePanacheQueryImpl<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/reactive/runtime/CommonReactivePanacheQueryImpl.java#L113-L149","documentation":"CommonReactivePanacheQueryImpl supports page-based navigation only after pagination has been initialized. Page navigation methods (nextPage, previousPage, firstPage, lastPage, hasNextPage, hasPreviousPage) call checkPagination() which throws UnsupportedOperationException when page is null.","triggerScenarios":"Calling nextPage()/previousPage()/firstPage()/lastPage()/hasNextPage()/hasPreviousPage() on a ReactivePanacheQuery without first calling page(Page) or page(int, int); also thrown when a range query (range(start,end)) was used instead of paging.","commonSituations":"Using range(...) then asking about pages; assuming a fresh query() result starts at page 0 automatically; porting blocking Panache code expecting the same defaults.","solutions":["Call query.page(0, size) (or page(Page.of(...))) before any page navigation method","If you used range(start, end), do not call page-related methods — iterate results directly","Check hasNextPage only after initializing pagination"],"exampleFix":"// before\nvar query = Customer.find(\"active\", true).range(0, 10);\nquery.hasNextPage(); // throws\n// after\nvar query = Customer.find(\"active\", true).page(0, 10);\nquery.hasNextPage();","handlingStrategy":"validation","validationCode":"ReactivePanacheQuery<Customer> q = Customer.find(\"active\", true);\nq.page(0, 20); // initialize pagination before any page navigation","typeGuard":null,"tryCatchPattern":"try {\n    boolean more = query.hasNextPage();\n} catch (UnsupportedOperationException e) {\n    query.page(0, 20);\n    boolean more = query.hasNextPage();\n}","preventionTips":["Always call page(Page) or page(int,int) right after creating the query","Never mix range() with page navigation methods","Wrap query construction in a helper that guarantees pagination setup"],"tags":["quarkus","mongodb-panache","pagination","reactive"],"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-14T00:17:10.932Z"}