{"record":{"id":"da52c3b34b3fa1fa","repo":"prestodb/presto","slug":"isnull-length-is-less-than-positioncount-da52c3","errorCode":null,"errorMessage":"isNull length is less than positionCount","messagePattern":"isNull 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":73,"sourceCode":"\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\n    public OptionalInt fixedSizeInBytesPerPosition()\n    {\n        return OptionalInt.of(SIZE_IN_BYTES_PER_POSITION);\n    }\n","sourceCodeStart":55,"sourceCodeEnd":91,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-common/src/main/java/com/facebook/presto/common/block/IntArrayBlock.java#L55-L91","documentation":"IntArrayBlock also validates the optional null bitmap: when valueIsNull is non-null, valueIsNull.length - arrayOffset must be >= positionCount so every position has a corresponding null flag. A too-short boolean[] throws IllegalArgumentException.","triggerScenarios":"Passing a valueIsNull array built for a different (larger) positionCount, or built without accounting for arrayOffset, while values happens to be long enough — so the mismatch surfaces on the null array check.","commonSituations":"Null bitmap and values arrays produced by separate code paths with different offsets; truncating only one of the two arrays; adapting blocks from another engine where the null mask excludes an offset region.","solutions":["Ensure valueIsNull is either null or has length >= arrayOffset + positionCount; rebuild the nulls array to match.","Apply the same arrayOffset/slicing to both arrays.","If nulls are absent, pass null explicitly instead of a short placeholder array."],"exampleFix":"// before\nboolean[] nulls = new boolean[count]; // missing offset room\nnew IntArrayBlock(offset, count, nulls, values);\n// after\nboolean[] nulls = new boolean[offset + count];\nnew IntArrayBlock(offset, count, nulls, values);","handlingStrategy":"validation","validationCode":"if (valueIsNull != null && valueIsNull.length - arrayOffset < positionCount) {\n    valueIsNull = Arrays.copyOf(valueIsNull, arrayOffset + positionCount); // pad to fit\n}","typeGuard":"boolean nullsFit(boolean[] valueIsNull, int arrayOffset, int positionCount) {\n    return valueIsNull == null || valueIsNull.length - arrayOffset >= positionCount;\n}","tryCatchPattern":"try {\n    block = new IntArrayBlock(offset, count, nulls, values);\n} catch (IllegalArgumentException e) {\n    nulls = nulls == null ? null : Arrays.copyOf(nulls, offset + count);\n    block = new IntArrayBlock(offset, count, nulls, values);\n}","preventionTips":["Apply the same arrayOffset to both values and nulls arrays","Rebuild or pad null bitmaps when positionCount changes","Pass null instead of a short placeholder when the block has no nulls"],"tags":["presto","block","illegal-argument","null-bitmap"],"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"}