{"record":{"id":"c3bd75f26a1dff89","repo":"quarkusio/quarkus","slug":"cannot-call-a-page-related-method-in-a-ranged-quer-c3bd75","errorCode":null,"errorMessage":"Cannot call a page related method in a ranged query, call page(Page) or page(int, int) to initiate pagination first","messagePattern":"Cannot call a page related method in a ranged query, 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":136,"sourceCode":"            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;\n        return (CommonReactivePanacheQueryImpl<T>) this;\n    }\n\n    public <T extends Entity> CommonReactivePanacheQueryImpl<T> withReadPreference(ReadPreference readPreference) {\n        this.collection = this.collection.withReadPreference(readPreference);","sourceCodeStart":118,"sourceCodeEnd":154,"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#L118-L154","documentation":"This UnsupportedOperationException is thrown by checkPagination() in CommonReactivePanacheQueryImpl. Panache queries support two mutually exclusive result-limiting modes: paging (page(Page)/page(int,int)) and ranging (range(int,int)). Page-navigation methods (nextPage, previousPage, firstPage, lastPage, hasNextPage, hasPreviousPage) require the query to be in paging mode with no range set, so they throw when the query was created with range() or when no page was ever set.","triggerScenarios":"Calling nextPage(), previousPage(), firstPage(), lastPage(), hasNextPage(), or hasPreviousPage() on a query on which range(startIndex, lastIndex) was called, or on which no page(Page)/page(int,int) was called at all (page == null).","commonSituations":"Developers mixing paging and range APIs on the same query; calling hasNextPage() on a query built for a one-off range fetch; refactoring code from page() to range() while keeping page-navigation calls; copying query-building code that ends with range() but retains UI pagination logic.","solutions":["Remove the range(...) call and use page(Page) or page(pageIndex, size) before calling any page-related method","If you need ranged fetching, replace page-navigation calls with list()/firstResult() and re-issue queries with adjusted range indices","Split the logic: use range() for single-shot fetches, page() only when you need hasNextPage/nextPage navigation"],"exampleFix":"// before\nvar query = reactiveFind(\"status = ?1\", \"OPEN\").range(0, 9);\nboolean more = query.hasNextPage(); // throws\n\n// after\nvar query = reactiveFind(\"status = ?1\", \"OPEN\").page(0, 10);\nboolean more = query.hasNextPage(); // works","handlingStrategy":"validation","validationCode":"if (query.getClass().getSimpleName().contains(\"ReactivePanacheQuery\")) {\n    // ensure paging mode before navigation\n    query.page(0, 20); // initialize page\n    // do NOT call range(...) if you will use nextPage/hasNextPage\n}","typeGuard":null,"tryCatchPattern":"try {\n    return query.hasNextPage();\n} catch (UnsupportedOperationException e) {\n    // query was ranged or paged never initialized; fall back to count + range\n    return false;\n}","preventionTips":["Pick one limiting mode per query: page() for navigation, range() for one-shot slices","Call page(Page) immediately after building the query if any page-related method may be used","Wrap pagination logic in a repository helper so page vs range is decided in one place"],"tags":["panache","mongodb","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"}