{"record":{"id":"8e84dad07ba40526","repo":"prestodb/presto","slug":"position-is-not-valid-8e84da","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/Int128ArrayBlockBuilder.java","lineNumber":439,"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(\"Int128ArrayBlockBuilder(%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 boolean isNullUnchecked(int internalPosition)\n    {\n        assert mayHaveNull() : \"no nulls present\";\n        assert internalPositionInRange(internalPosition, getOffsetBase(), getPositionCount());\n        return valueIsNull[internalPosition];\n    }","sourceCodeStart":421,"sourceCodeEnd":457,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-common/src/main/java/com/facebook/presto/common/block/Int128ArrayBlockBuilder.java#L421-L457","documentation":"checkReadablePosition guards every position-based read on Int128ArrayBlockBuilder (getLong, isNull, writePositionTo, getSingleValueBlock, copyPositions). Any position outside [0, getPositionCount()) is rejected with IllegalArgumentException because the builder has no value at that index.","triggerScenarios":"Reading at a position equal to or greater than positionCount — commonly position == positionCount when iterating with <=, reading after an unfinished entry, or using stale indexes after the builder grew/reset.","commonSituations":"Off-by-one loops over block positions; reading a builder before closeEntry/finalization changed positionCount; reusing cached position indexes after block rebuild or page operator restarts.","solutions":["Clamp/validate the loop bound: iterate i < block.getPositionCount().","Only read after entries are closed (closeEntry) so positionCount reflects written values.","Re-fetch positions from the current block instance instead of caching indexes across rebuilds."],"exampleFix":"// before\nfor (int i = 0; i <= block.getPositionCount(); i++) { block.isNull(i); }\n// after\nfor (int i = 0; i < block.getPositionCount(); i++) { block.isNull(i); }","handlingStrategy":"validation","validationCode":"if (position < 0 || position >= block.getPositionCount()) {\n    throw new IllegalArgumentException(\"position out of range: \" + position);\n}","typeGuard":"boolean readablePosition(Block b, int position) {\n    return position >= 0 && position < b.getPositionCount();\n}","tryCatchPattern":"try {\n    value = builder.getLong(position, offset);\n} catch (IllegalArgumentException e) {\n    log.warn(\"Bad position {} on builder with {} positions\", position, builder.getPositionCount());\n    return null;\n}","preventionTips":["Iterate with i < getPositionCount(), never <=","Close all entries before reading back from a builder","Do not cache position indexes across block rebuilds or page restarts"],"tags":["presto","block","illegal-argument","bounds-check"],"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"}