{"record":{"id":"b87ab8953875746f","repo":"quarkusio/quarkus","slug":"cannot-call-a-range-related-method-call-range-int-b87ab8","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-reactive-panache-common/runtime/src/main/java/io/quarkus/hibernate/reactive/panache/common/runtime/CommonAbstractPanacheQueryImpl.java","lineNumber":222,"sourceCode":"            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 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        // reset the page to its default to be able to switch from page to range\n        this.page = null;\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 void withLock(LockModeType lockModeType) {\n        this.lockModeType = lockModeType;\n    }\n\n    public void withHint(String hintName, Object value) {\n        if (hints == null) {\n            hints = new HashMap<>();\n        }\n        hints.put(hintName, value);\n        throw new UnsupportedOperationException(\"Hints not supported yet\");","sourceCodeStart":204,"sourceCodeEnd":240,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/extensions/panache/hibernate-reactive-panache-common/runtime/src/main/java/io/quarkus/hibernate/reactive/panache/common/runtime/CommonAbstractPanacheQueryImpl.java#L204-L240","documentation":"Thrown by CommonAbstractPanacheQueryImpl.checkRange when a range accessor method is called on a query whose Range state is null, i.e. range(int,int) was never invoked. Panache treats paging and ranging as mutually exclusive modes on a query; range accessors require ranged mode to be initialized first. It is an UnsupportedOperationException indicating incorrect API sequencing.","triggerScenarios":"Calling range() (the accessor) or any range-related method on a PanacheQuery before calling range(int startIndex, int lastIndex).","commonSituations":"Developers build a query and try to read back the configured range for logging/pagination logic without setting one; code paths conditionally call range() assuming it was configured upstream.","solutions":["Call range(int startIndex, int lastIndex) on the PanacheQuery before accessing range-related methods.","If the query is meant to be paged, switch the code to page(Page)/page(int,int) and page-related accessors.","Guard the accessor call with your own knowledge of whether a range was set (track it in application code)."],"exampleFix":"// before\nPanacheQuery<Person> q = Person.find(\"age > ?1\", 18);\nRange r = q.range(); // UnsupportedOperationException\n\n// after\nPanacheQuery<Person> q = Person.find(\"age > ?1\", 18).range(0, 50);\nRange r = q.range();","handlingStrategy":"validation","validationCode":"if (!rangedInitialized) { throw new IllegalStateException(\"call range(int, int) before reading the range\"); }","typeGuard":null,"tryCatchPattern":"try { Range r = query.range(); } catch (UnsupportedOperationException e) { query.range(0, defaultLast); Range r = query.range(); }","preventionTips":["Call range(int startIndex, int lastIndex) before any range accessor","Decide up front whether a query is paged or ranged; track that in your DAO layer"],"tags":["panache","hibernate-reactive","range","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"}