{"record":{"id":"35468a00d6ccb669","repo":"quarkusio/quarkus","slug":"cannot-call-a-range-related-method-call-range-int","errorCode":null,"errorMessage":"Cannot call a range related method, call range(int, int) to initiate range first","messagePattern":"Cannot call a range related method, call range\\(int, int\\) to initiate range first","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"extensions/panache/hibernate-orm-panache-common/runtime/src/main/java/io/quarkus/hibernate/orm/panache/common/runtime/CommonPanacheQueryImpl.java","lineNumber":298,"sourceCode":"    public Page page() {\n        checkPagination();\n        return page;\n    }\n\n    private void checkPagination() {\n        if (page == null && keyedPage == null) {\n            throw new UnsupportedOperationException(\"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    private void checkRange() {\n        if (range == null) {\n            throw new UnsupportedOperationException(\"Cannot call a range related method, \" +\n                    \"call range(int, int) to initiate range first\");\n        }\n        if (page != null) {\n            throw new UnsupportedOperationException(\"Cannot call a range related method in a paged query, \" +\n                    \"call range(int, int) to initiate range first\");\n        }\n    }\n\n    public Range range() {\n        checkRange();\n        return range;\n    }\n\n    public void range(int startIndex, int lastIndex) {\n        this.range = Range.of(startIndex, lastIndex);\n        this.page = null;\n        this.keyedPage = null;\n        this.lastKeyedResult = null;","sourceCodeStart":280,"sourceCodeEnd":316,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/extensions/panache/hibernate-orm-panache-common/runtime/src/main/java/io/quarkus/hibernate/orm/panache/common/runtime/CommonPanacheQueryImpl.java#L280-L316","documentation":"Thrown by the Hibernate ORM Panache query's range guard when a range-related accessor is called on a query that never had range(int, int) applied. Panache queries can be in one pagination mode — page, keyed page, or range; calling a range method (mirroring the sibling checkPagination guard that rejects page methods without page(...)) without first initiating a range leaves the range state null, and the guard prevents reading an undefined range.","triggerScenarios":"Calling query.range() (the accessor returning Range) on a PanacheQuery where range(int, int) was never invoked.","commonSituations":"Assuming a default range exists; reading back query window settings that were never configured.","solutions":["Call range(int from, int to) before reading the range().","Use page(Page) if you actually meant pagination, then read page() instead of range().","Handle the absent-range case in your code before accessing the accessor."],"exampleFix":"// before\nPanacheQuery<Person> q = Person.find(\"status\", \"active\");\nRange r = q.range(); // throws\n\n// after\nPanacheQuery<Person> q = Person.find(\"status\", \"active\").range(0, 49);\nRange r = q.range();","handlingStrategy":"validation","validationCode":"if (rangeWasNotSet) {\n    query.range(0, defaultTo - 1);\n}\nRange r = query.range();","typeGuard":null,"tryCatchPattern":"try {\n    return query.range();\n} catch (UnsupportedOperationException e) {\n    return null; // no range configured\n}","preventionTips":["Call range(from, to) before reading range().","Only use the range() accessor in code paths that configured a range.","Prefer pagination APIs unless a fixed window is genuinely required."],"tags":["panache","range","unsupported-operation","call-order"],"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"}