{"record":{"id":"cded4ee7cb723a14","repo":"prestodb/presto","slug":"positioncount-is-negative-cded4e","errorCode":null,"errorMessage":"positionCount is negative","messagePattern":"positionCount is negative","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"presto-common/src/main/java/com/facebook/presto/common/block/Int128ArrayBlock.java","lineNumber":69,"sourceCode":"    @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);\n    }\n\n    @Override\n    public long getSizeInBytes()","sourceCodeStart":51,"sourceCodeEnd":87,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-common/src/main/java/com/facebook/presto/common/block/Int128ArrayBlock.java#L51-L87","documentation":"A block cannot have a negative number of positions. The Int128ArrayBlock constructor validates positionCount >= 0 and throws IllegalArgumentException if it is negative, since all downstream reads iterate that many positions.","triggerScenarios":"Constructing Int128ArrayBlock with a negative positionCount, usually from a subtraction like endPosition - startPosition where end < start, or an uninitialized count variable.","commonSituations":"Page splitting/merging code where range arithmetic went backwards; off-by-one fixes that inverted a subtraction; deserializers reading a corrupt negative count from a serialized page.","solutions":["Clamp the computed count: int count = Math.max(0, end - start).","Assert end >= start before constructing the block so the real bug (wrong range order) surfaces at the source.","If the count came from serialized data, validate it against the remaining buffer size before use."],"exampleFix":"// before\nInt128ArrayBlock block = new Int128ArrayBlock(0, end - start, isNull, values);\n// after\ncheckArgument(end >= start, \"invalid range [%s, %s)\", start, end);\nInt128ArrayBlock block = new Int128ArrayBlock(0, end - start, isNull, values);","handlingStrategy":"validation","validationCode":"checkArgument(end >= start, \"invalid range [%s, %s): positionCount would be negative\", start, end);\nint positionCount = end - start;","typeGuard":"boolean validPositionCount(int positionCount) { return positionCount >= 0; }","tryCatchPattern":"try {\n    block = new Int128ArrayBlock(0, positionCount, isNull, values);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().contains(\"positionCount is negative\")) {\n        throw new IllegalStateException(\"range computation gave negative count \" + positionCount, e);\n    }\n    throw e;\n}","preventionTips":["Order-check start/end before subtraction.","If counts come from serialized pages, validate them against remaining payload size.","Use checkArgument-style guards at every block construction site."],"tags":["presto","block","constructor-validation","illegal-argument"],"backgroundTag":"negative-position-count","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"}