{"record":{"id":"2bd212ddb41b6082","repo":"prestodb/presto","slug":"position-is-not-valid-2bd212","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/ByteArrayBlock.java","lineNumber":249,"sourceCode":"        return new ByteArrayBlock(0, length, newValueIsNull, newValues);\n    }\n\n    @Override\n    public String getEncodingName()\n    {\n        return ByteArrayBlockEncoding.NAME;\n    }\n\n    @Override\n    public String toString()\n    {\n        return format(\"ByteArrayBlock(%d){positionCount=%d}\", hashCode(), getPositionCount());\n    }\n\n    private void checkReadablePosition(int position)\n    {\n        if (position < 0 || position >= getPositionCount()) {\n            throw new IllegalArgumentException(\"position is not valid\");\n        }\n    }\n\n    @Override\n    public int getOffsetBase()\n    {\n        return arrayOffset;\n    }\n\n    @Override\n    public boolean isNullUnchecked(int internalPosition)\n    {\n        assert mayHaveNull() : \"no nulls present\";\n        assert internalPositionInRange(internalPosition, getOffsetBase(), getPositionCount());\n        return valueIsNull[internalPosition];\n    }\n\n    @Override","sourceCodeStart":231,"sourceCodeEnd":267,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-common/src/main/java/com/facebook/presto/common/block/ByteArrayBlock.java#L231-L267","documentation":"ByteArrayBlock.checkReadablePosition throws IllegalArgumentException when a caller asks for a position outside the valid range [0, getPositionCount()). Read APIs such as getByte, isNull, writePositionTo, getSingleValueBlock, copyPositions and toLong all funnel through this guard so the block never reads out of bounds.","triggerScenarios":"Calling block.getByte(position) or block.isNull(position) with position < 0 or position >= block.getPositionCount(); iterating with a stale/hardcoded position count; copyPositions with a positions array containing out-of-range indexes; using a position from a different (larger) block.","commonSituations":"Loops bounded by a wrong variable (e.g. logical row count vs physical block positionCount); aggregating blocks from pages with differing row counts after a filter; operator code caching a positionCount before a block was trimmed or reassigned.","solutions":["Clamp/bound loops with block.getPositionCount() rather than an external row count","Check 0 <= position && position < block.getPositionCount() before each read","Verify the positions array passed to copyPositions contains only indexes within range","Trace where the invalid position originates — usually an upstream page or operator produced fewer rows than expected"],"exampleFix":"// before\nfor (int i = 0; i < expectedRows; i++) value = block.getByte(i); // may throw\n// after\nfor (int i = 0; i < block.getPositionCount(); i++) value = block.getByte(i);","handlingStrategy":"validation","validationCode":"if (position < 0 || position >= block.getPositionCount()) {\n    throw new IllegalArgumentException(\"position \" + position + \" out of range [0, \" + block.getPositionCount() + \")\");\n}\nbyte value = block.getByte(position);\n","typeGuard":"boolean isReadablePosition(Block block, int position) {\n    return position >= 0 && position < block.getPositionCount();\n}\n","tryCatchPattern":"try {\n    byte v = block.getByte(position);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().contains(\"position is not valid\")) {\n        throw new IllegalStateException(\"read past block end; positionCount=\" + block.getPositionCount());\n    }\n    throw e;\n}\n","preventionTips":["Iterate with i < block.getPositionCount(), never with external expected-row counts","Re-read positionCount after any operation that may trim/reassign the block","Validate positions arrays before copyPositions"],"tags":["presto","bounds-check","illegal-argument","block-access"],"backgroundTag":"index-out-of-bounds","analyzedSha":"55bb57d202de3b926896fa966c2c4a44c779634e","analyzedAt":"2026-09-04T12:50:26.162Z","contentChangedAt":"2026-09-04T12:50:26.162Z","schemaVersion":2},"datasetVersion":"2026-09-12T02:17:10.037Z"}