{"record":{"id":"e517a86818ff825f","repo":"prestodb/presto","slug":"position-is-not-valid-e517a8","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/Int128ArrayBlock.java","lineNumber":337,"sourceCode":"        return new Int128ArrayBlock(0, length, newValueIsNull, newValues);\n    }\n\n    @Override\n    public String getEncodingName()\n    {\n        return Int128ArrayBlockEncoding.NAME;\n    }\n\n    @Override\n    public String toString()\n    {\n        return format(\"Int128ArrayBlock(%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 long getLongUnchecked(int internalPosition, int offset)\n    {\n        assert internalPositionInRange(internalPosition, getOffsetBase(), getPositionCount());\n        assert offset == 0 || offset == 8 : \"offset must be 0 or 8\";\n        return values[internalPosition * 2 + bitCount(offset)];\n    }\n\n    @Override\n    public int getOffsetBase()\n    {\n        return positionOffset;\n    }\n\n    @Override","sourceCodeStart":319,"sourceCodeEnd":355,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-common/src/main/java/com/facebook/presto/common/block/Int128ArrayBlock.java#L319-L355","documentation":"checkReadablePosition guards every public position-accessing method of Int128ArrayBlock (getLong, isNull, writePositionTo, getSingleValueBlock, copyPositions). Any position outside [0, getPositionCount()) is invalid because the block only exposes its visible position range; IllegalArgumentException is thrown rather than reading out of bounds.","triggerScenarios":"Calling any accessor with position < 0 or position >= getPositionCount(); iterating with a stale position count after the block was replaced by a region/getRegion view with fewer positions; using an absolute source position on a sliced block instead of a relative one.","commonSituations":"Operators caching a position index across page boundaries; using the parent block's positions on a getRegion result; off-by-one loops written as i <= positionCount; reusing positions from a previous page whose count was larger.","solutions":["Clamp/bound loops with the block's own getPositionCount(): for (int i = 0; i < block.getPositionCount(); i++).","Translate parent-block positions to region-relative positions before calling accessors on a region view.","Check position bounds explicitly before access when the position comes from external input (e.g. join probes, output channel indices)."],"exampleFix":"// before\nfor (int i = 0; i <= region.getPositionCount(); i++) { region.isNull(i); } // off-by-one\n// after\nfor (int i = 0; i < region.getPositionCount(); i++) { region.isNull(i); }","handlingStrategy":"type-guard","validationCode":"if (position < 0 || position >= block.getPositionCount()) {\n    throw new IllegalArgumentException(\"position \" + position + \" out of range for block with \" + block.getPositionCount() + \" positions\");\n}","typeGuard":"boolean isReadablePosition(Block block, int position) {\n    return position >= 0 && position < block.getPositionCount();\n}","tryCatchPattern":"try {\n    value = block.getLong(position, 0);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().contains(\"position is not valid\")) {\n        throw new IllegalStateException(\"stale position \" + position + \" for block count \" + block.getPositionCount(), e);\n    }\n    throw e;\n}","preventionTips":["Bound all loops with the block's own getPositionCount(), never a cached count.","Convert parent positions to region-relative positions after getRegion/getPositionRange.","Reuse position indexes only within the same page; revalidate across pages."],"tags":["presto","block","bounds-check","position-out-of-range"],"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"}