{"record":{"id":"dbe13954f2c239b3","repo":"prestodb/presto","slug":"position-is-not-valid-dbe139","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/ByteArrayBlockBuilder.java","lineNumber":328,"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(\"ByteArrayBlockBuilder(%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 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\n    public byte getByteUnchecked(int internalPosition)\n    {\n        assert internalPositionInRange(internalPosition, getOffsetBase(), getPositionCount());\n        return values[internalPosition];\n    }\n","sourceCodeStart":310,"sourceCodeEnd":346,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-common/src/main/java/com/facebook/presto/common/block/ByteArrayBlockBuilder.java#L310-L346","documentation":"ByteArrayBlockBuilder.checkReadablePosition throws IllegalArgumentException when a position argument is negative or >= getPositionCount() of the builder's currently built region. It guards the same read APIs as ByteArrayBlock (getByte, isNull, writePositionTo, getSingleValueBlock, copyPositions) while the values still live in the builder.","triggerScenarios":"Reading from a ByteArrayBlockBuilder with position >= getPositionCount(), e.g. calling getByte(positionCount) before build() flushes the last value; forgetting that appended-but-not-finished values may not count; using positions from a differently sized block; negative positions from unvalidated input.","commonSituations":"Custom aggregation/accumulator code reading builder positions before closing the entry (missing builder.closeEntry()); copying data between blocks whose position counts differ; testing code assuming unread appended values are immediately visible.","solutions":["Call builder.getPositionCount() and bound all reads to it, reading positions 0..positionCount-1","Ensure closeEntry() is invoked after writing each value so appended values become readable positions","Use build() to convert to a Block before random-position reads if the region semantics are unclear","Validate incoming position arrays before calling copyPositions on a builder"],"exampleFix":"// before\nbuilder.writeByte(7); int v = builder.getByte(builder.getPositionCount()); // throws\n// after\nbuilder.writeByte(7); builder.closeEntry(); int v = builder.getByte(builder.getPositionCount() - 1);","handlingStrategy":"validation","validationCode":"int count = builder.getPositionCount();\nif (position < 0 || position >= count) {\n    throw new IllegalArgumentException(\"position \" + position + \" out of range [0, \" + count + \")\");\n}\nbyte v = builder.getByte(position);\n","typeGuard":"boolean builderHasPosition(ByteArrayBlockBuilder builder, int position) {\n    return position >= 0 && position < builder.getPositionCount();\n}\n","tryCatchPattern":"try {\n    byte v = builder.getByte(position);\n} catch (IllegalArgumentException e) {\n    throw new IllegalStateException(\"builder position out of range; call closeEntry()/build() before reading\", e);\n}\n","preventionTips":["Call closeEntry() after each value write so appended values count as readable positions","Bound reads with builder.getPositionCount() fetched immediately before the read","Prefer builder.build() for random-position reads"],"tags":["presto","bounds-check","illegal-argument","block-builder"],"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-11T21:17:09.523Z"}