{"record":{"id":"14cbe79db48ed9a2","repo":"prestodb/presto","slug":"position-is-not-valid-14cbe7","errorCode":null,"errorMessage":"position is not valid: ","messagePattern":"position is not valid: ","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"presto-common/src/main/java/com/facebook/presto/common/block/RunLengthEncodedBlock.java","lineNumber":343,"sourceCode":"    {\n        return format(\"RunLengthEncodedBlock(%d){positionCount=%d,value=%s}\", hashCode(), getPositionCount(), value);\n    }\n\n    @Override\n    public Block getLoadedBlock()\n    {\n        Block loadedValueBlock = value.getLoadedBlock();\n\n        if (loadedValueBlock == value) {\n            return this;\n        }\n        return new RunLengthEncodedBlock(loadedValueBlock, positionCount);\n    }\n\n    private void checkReadablePosition(int position)\n    {\n        if (position < 0 || position >= positionCount) {\n            throw new IllegalArgumentException(\"position is not valid: \" + position);\n        }\n    }\n\n    @Override\n    public byte getByteUnchecked(int internalPosition)\n    {\n        assert internalPositionInRange(internalPosition, getOffsetBase(), getPositionCount());\n        return value.getByte(0);\n    }\n\n    @Override\n    public short getShortUnchecked(int internalPosition)\n    {\n        assert internalPositionInRange(internalPosition, getOffsetBase(), getPositionCount());\n        return value.getShort(0);\n    }\n\n    @Override","sourceCodeStart":325,"sourceCodeEnd":361,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-common/src/main/java/com/facebook/presto/common/block/RunLengthEncodedBlock.java#L325-L361","documentation":"RunLengthEncodedBlock.checkReadablePosition validates that a requested position lies within [0, positionCount). All primitive accessors (getLong, getInt, getSlice, etc.) route through it. Because all positions read the same underlying value, only the outer bounds matter — but an out-of-range index means the caller is addressing positions that do not exist in this block.","triggerScenarios":"Reading block position >= getPositionCount() or < 0, e.g. iterating with a stale position count after a block was compacted/filtered, or indexing with a source position from a different block.","commonSituations":"Operators holding an old positionCount snapshot after page slicing; off-by-one loops (position <= count); copying positions across blocks with different sizes during page reshuffling.","solutions":["Bounds-check position against the current block's getPositionCount() before access","Re-fetch the block/position count after any transform instead of caching stale counts","Fix loop conditions to position < positionCount (not <=)","Ensure the position passed belongs to the same block instance being read"],"exampleFix":"// before\nfor (int i = 0; i <= block.getPositionCount(); i++) { // off-by-one\n    long v = block.getLong(i, 0);\n}\n// after\nfor (int i = 0; i < block.getPositionCount(); i++) {\n    long v = block.getLong(i, 0);\n}","handlingStrategy":"validation","validationCode":"// before reading any position from an RLE block\nif (position < 0 || position >= block.getPositionCount()) {\n    throw new IllegalArgumentException(\"position \" + position + \" out of range for block with \" + block.getPositionCount() + \" positions\");\n}\nlong v = block.getLong(position, 0);\n","typeGuard":null,"tryCatchPattern":"try {\n    return block.getLong(position, 0);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().startsWith(\"position is not valid\")) {\n        throw new IllegalStateException(\"stale position \" + position + \" vs current count \" + block.getPositionCount() + \"; refresh block reference\", e);\n    }\n    throw e;\n}","preventionTips":["Never cache positionCount across block transformations","Use strict < comparisons in position loops","Verify positions come from the same block instance (especially after page slicing)"],"tags":["presto","rle-block","index-out-of-bounds","blocks"],"backgroundTag":"block-position-out-of-range","analyzedSha":"55bb57d202de3b926896fa966c2c4a44c779634e","analyzedAt":"2026-09-04T12:50:26.162Z","contentChangedAt":"2026-09-04T12:50:26.162Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}