{"record":{"id":"7a8b690d12c4d83a","repo":"prestodb/presto","slug":"position-is-not-valid-7a8b69","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/ShortArrayBlock.java","lineNumber":240,"sourceCode":"        return new ShortArrayBlock(0, length, newValueIsNull, newValues);\n    }\n\n    @Override\n    public String getEncodingName()\n    {\n        return ShortArrayBlockEncoding.NAME;\n    }\n\n    @Override\n    public String toString()\n    {\n        return format(\"ShortArrayBlock(%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 short getShortUnchecked(int internalPosition)\n    {\n        assert internalPositionInRange(internalPosition, getOffsetBase(), getPositionCount());\n        return values[internalPosition];\n    }\n\n    @Override\n    public int getOffsetBase()\n    {\n        return arrayOffset;\n    }\n\n    @Override\n    public boolean isNullUnchecked(int internalPosition)","sourceCodeStart":222,"sourceCodeEnd":258,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-common/src/main/java/com/facebook/presto/common/block/ShortArrayBlock.java#L222-L258","documentation":"checkReadablePosition guards every positional read on ShortArrayBlock (getShort, isNull, writePositionTo, getSingleValueBlock, copyPositions, etc.). Any position outside [0, positionCount) is invalid and throws IllegalArgumentException(\"position is not valid\"). It prevents silent out-of-bounds access into the internal values array.","triggerScenarios":"Calling getShort/isNull/writePositionTo/getSingleValueBlock/copyPositions/toLong on a ShortArrayBlock with position < 0 or position >= positionCount.","commonSituations":"Off-by-one loops using <= positionCount, using a raw position into an enclosing block instead of the sliced block's internal position, iterating a single-value block with stale indices, using absolute row numbers against a sliced/paginated block.","solutions":["Clamp the loop to positionCount: for (int i = 0; i < block.getPositionCount(); i++).","When working with sliced blocks, convert outer positions to internal ones (position - getRangeStartOffset) before reading.","Null-check or bounds-check the position before calling the accessor."],"exampleFix":"// before\nfor (int i = 0; i <= block.getPositionCount(); i++) {\n    short v = block.getShort(i, 0);\n}\n// after\nfor (int i = 0; i < block.getPositionCount(); i++) {\n    short v = block.getShort(i, 0);\n}","handlingStrategy":"validation","validationCode":"if (position < 0 || position >= block.getPositionCount()) {\n    throw new IllegalArgumentException(\"position \" + position + \" out of range [0, \" + block.getPositionCount() + \")\");\n}","typeGuard":"boolean isReadablePosition(Block block, int position) {\n    return position >= 0 && position < block.getPositionCount();\n}","tryCatchPattern":"try {\n    short v = shortArrayBlock.getShort(position, 0);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().equals(\"position is not valid\")) {\n        throw new IllegalStateException(\"Bad position \" + position + \" for block with \" + shortArrayBlock.getPositionCount() + \" positions\", e);\n    }\n    throw e;\n}","preventionTips":["Iterate with i < block.getPositionCount(), never <=.","Convert outer/absolute positions to internal ones for sliced blocks (position - getRangeStartOffset).","Prefer checked accessors only inside loops bounded by getPositionCount(); use getShortUnchecked only when the bound is proven."],"tags":["presto","block","bounds-check","position-out-of-range"],"backgroundTag":"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"}