{"record":{"id":"b08dd4c522ee1e61","repo":"prestodb/presto","slug":"positionoffset-is-negative","errorCode":null,"errorMessage":"positionOffset is negative","messagePattern":"positionOffset is negative","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"presto-common/src/main/java/com/facebook/presto/common/block/Int128ArrayBlock.java","lineNumber":65,"sourceCode":"    public static final int SIZE_IN_BYTES_PER_POSITION = INT128_BYTES + Byte.BYTES;\n\n    private final int positionOffset;\n    private final int positionCount;\n    @Nullable\n    private final boolean[] valueIsNull;\n    private final long[] values;\n\n    private final long retainedSizeInBytes;\n\n    public Int128ArrayBlock(int positionCount, Optional<boolean[]> valueIsNull, long[] values)\n    {\n        this(0, positionCount, valueIsNull.orElse(null), values);\n    }\n\n    Int128ArrayBlock(int positionOffset, int positionCount, boolean[] valueIsNull, long[] values)\n    {\n        if (positionOffset < 0) {\n            throw new IllegalArgumentException(\"positionOffset is negative\");\n        }\n        this.positionOffset = positionOffset;\n        if (positionCount < 0) {\n            throw new IllegalArgumentException(\"positionCount is negative\");\n        }\n        this.positionCount = positionCount;\n\n        if (values.length - (positionOffset * 2) < positionCount * 2) {\n            throw new IllegalArgumentException(\"values length is less than positionCount\");\n        }\n        this.values = values;\n\n        if (valueIsNull != null && valueIsNull.length - positionOffset < positionCount) {\n            throw new IllegalArgumentException(\"isNull length is less than positionCount\");\n        }\n        this.valueIsNull = valueIsNull;\n\n        retainedSizeInBytes = INSTANCE_SIZE + sizeOf(valueIsNull) + sizeOf(values);","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-common/src/main/java/com/facebook/presto/common/block/Int128ArrayBlock.java#L47-L83","documentation":"Int128ArrayBlock supports viewing a sub-range of the underlying long[] via positionOffset. A negative offset is meaningless, so the package-private constructor throws IllegalArgumentException immediately.","triggerScenarios":"Constructing Int128ArrayBlock directly (or via a region/view helper) with a negative positionOffset, e.g. a computed region start like parentOffset - delta that went below zero.","commonSituations":"Operator code computing slice offsets with signed arithmetic (subtraction on region starts), page slicing where a start position was clamped incorrectly, custom serializers building blocks from partially filled buffers.","solutions":["Clamp or recompute the offset before construction: ensure positionOffset >= 0 (e.g. Math.max(0, start)).","If the region logically starts before the buffer, slice the arrays correctly and pass offset 0 with adjusted arrays.","Validate upstream arithmetic that produced the offset."],"exampleFix":"// before\nInt128ArrayBlock block = new Int128ArrayBlock(regionStart, count, isNull, values); // regionStart < 0\n// after\nint safeStart = Math.max(0, regionStart);\nInt128ArrayBlock block = new Int128ArrayBlock(safeStart, count, isNull, values);","handlingStrategy":"validation","validationCode":"checkArgument(positionOffset >= 0, \"positionOffset must be >= 0, got %s\", positionOffset);","typeGuard":"boolean validOffset(int positionOffset) { return positionOffset >= 0; }","tryCatchPattern":"try {\n    block = new Int128ArrayBlock(offset, count, isNull, values);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().contains(\"positionOffset is negative\")) {\n        throw new IllegalStateException(\"region arithmetic produced negative offset \" + offset, e);\n    }\n    throw e;\n}","preventionTips":["Clamp region starts with Math.max(0, start) before constructing blocks.","Add assertions on offset arithmetic in slicing code.","Never pass computed offsets straight into block constructors without a bounds check."],"tags":["presto","block","constructor-validation","illegal-argument"],"backgroundTag":"negative-offset-parameter","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"}