{"record":{"id":"fee1240d892964b4","repo":"prestodb/presto","slug":"position-is-not-valid-fee124","errorCode":null,"errorMessage":"position is not valid","messagePattern":"position is not valid","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"presto-common/src/main/java/com/facebook/presto/common/block/AbstractSingleArrayBlock.java","lineNumber":36,"sourceCode":"\nimport static com.facebook.presto.common.block.BlockUtil.internalPositionInRange;\n\npublic abstract class AbstractSingleArrayBlock\n        implements Block\n{\n    protected final int start;\n\n    protected AbstractSingleArrayBlock(int start)\n    {\n        this.start = start;\n    }\n\n    protected abstract Block getBlock();\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 getSliceLength(int position)\n    {\n        checkReadablePosition(position);\n        return getBlock().getSliceLength(position + start);\n    }\n\n    @Override\n    public byte getByte(int position)\n    {\n        checkReadablePosition(position);\n        return getBlock().getByte(position + start);\n    }\n\n    @Override","sourceCodeStart":18,"sourceCodeEnd":54,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-common/src/main/java/com/facebook/presto/common/block/AbstractSingleArrayBlock.java#L18-L54","documentation":"AbstractSingleArrayBlock.checkReadablePosition validates that a position passed to element accessors (getSliceLength, getByte, getShort, getInt, getLong, getSlice) lies within [0, getPositionCount()). An out-of-range position throws IllegalArgumentException \"position is not valid\". Note positions here index the array elements of the single-element array block, not the underlying array.","triggerScenarios":"Calling element getters with position < 0 or >= the array element count, e.g. using the raw array block's positions or iterating over the wrong size.","commonSituations":"Expression evaluators mis-computing element positions inside array access; off-by-one loops over array elements; confusing the single-array block position space with the underlying block's position space.","solutions":["Bound loops by getPositionCount() of the AbstractSingleArrayBlock (array size), not the underlying value block.","Use ArrayBlock.getUnderlyingValueBlock/position mapping helpers to convert positions when crossing block boundaries.","Validate index expressions in the operator that produced the subscript before reading elements."],"exampleFix":"// before\nBlock arrayBlock = ...;\nfor (int i = 0; i < rawArray.getPositionCount(); i++) {\n    process(arrayBlock, i); // wrong position space\n}\n// after\nfor (int i = 0; i < arrayBlock.getPositionCount(); i++) {\n    process(arrayBlock, i);\n}","handlingStrategy":"type-guard","validationCode":"static boolean isValidArrayPosition(Block arrayBlock, int position) {\n    return position >= 0 && position < arrayBlock.getPositionCount();\n}","typeGuard":"static boolean canRead(Block singleArrayBlock, int position) {\n    return position >= 0 && position < singleArrayBlock.getPositionCount();\n}","tryCatchPattern":"try {\n    long v = arrayBlock.getLong(position);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage() != null && e.getMessage().equals(\"position is not valid\")) {\n        throw new IndexOutOfBoundsException(\"array element index out of range: \" + position);\n    }\n    throw e;\n}","preventionTips":["Use the single-array block's getPositionCount() (array element count) to bound iterations, not the underlying block's.","Map positions across block boundaries with the block's offset helpers.","Write expression-evaluator tests covering empty arrays and boundary indices."],"tags":["presto","block","array-block","bounds-check","illegal-argument"],"backgroundTag":"position-out-of-bounds","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"}