{"record":{"id":"ba5cf9fba585c4aa","repo":"prestodb/presto","slug":"values-length-is-less-than-positioncount-ba5cf9","errorCode":null,"errorMessage":"values length is less than positionCount","messagePattern":"values length is less than positionCount","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"presto-common/src/main/java/com/facebook/presto/common/block/IntArrayBlock.java","lineNumber":68,"sourceCode":"\n    public IntArrayBlock(int positionCount, Optional<boolean[]> valueIsNull, int[] values)\n    {\n        this(0, positionCount, valueIsNull.orElse(null), values);\n    }\n\n    IntArrayBlock(int arrayOffset, int positionCount, boolean[] valueIsNull, int[] values)\n    {\n        if (arrayOffset < 0) {\n            throw new IllegalArgumentException(\"arrayOffset is negative\");\n        }\n        this.arrayOffset = arrayOffset;\n        if (positionCount < 0) {\n            throw new IllegalArgumentException(\"positionCount is negative\");\n        }\n        this.positionCount = positionCount;\n\n        if (values.length - arrayOffset < positionCount) {\n            throw new IllegalArgumentException(\"values length is less than positionCount\");\n        }\n        this.values = values;\n\n        if (valueIsNull != null && valueIsNull.length - arrayOffset < 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()\n    {\n        return SIZE_IN_BYTES_PER_POSITION * (long) positionCount;\n    }\n\n    @Override","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-common/src/main/java/com/facebook/presto/common/block/IntArrayBlock.java#L50-L86","documentation":"IntArrayBlock checks that the backing int[] values array has enough room: values.length - arrayOffset must be >= positionCount. If the array cannot supply that many positions from arrayOffset onward, the constructor throws IllegalArgumentException to prevent out-of-bounds reads later.","triggerScenarios":"Constructing the block with a values array shorter than arrayOffset + positionCount — e.g. shrinking a buffer without adjusting positionCount, or reusing a constructor call's stale count after compacting the array.","commonSituations":"Buffer reuse pools where the array was reallocated smaller; off-by-one in capacity math when appending; callers passing positionCount that includes entries trimmed from the array.","solutions":["Ensure values.length >= arrayOffset + positionCount before constructing (grow the array or reduce positionCount).","Recompute positionCount as the actual number of ints available (values.length - arrayOffset) when the array is the source of truth.","Verify the array wasn't reallocated/truncated after the count was computed."],"exampleFix":"// before\nIntArrayBlock block = new IntArrayBlock(offset, values.length + 1, nulls, values);\n// after\nIntArrayBlock block = new IntArrayBlock(offset, values.length - offset, nulls, values);","handlingStrategy":"validation","validationCode":"if (values.length - arrayOffset < positionCount) {\n    throw new IllegalArgumentException(\"values array too small for offset+count\");\n}\nIntArrayBlock block = new IntArrayBlock(arrayOffset, positionCount, valueIsNull, values);","typeGuard":"boolean valuesFit(int[] values, int arrayOffset, int positionCount) {\n    return values != null && values.length - arrayOffset >= positionCount;\n}","tryCatchPattern":"try {\n    block = new IntArrayBlock(offset, count, nulls, values);\n} catch (IllegalArgumentException e) {\n    block = new IntArrayBlock(offset, values.length - offset, nulls, values); // clamp count\n}","preventionTips":["Recompute positionCount from the array whenever the array is authoritative","Grow arrays before constructing blocks that reference more positions","Check for arrays reallocated smaller by pooling/reuse code"],"tags":["presto","block","illegal-argument","array-length"],"backgroundTag":"buffer-size-mismatch","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"}