{"record":{"id":"7b70ee69fe8dc4b1","repo":"prestodb/presto","slug":"valueisnull-length-is-less-than-positioncount","errorCode":null,"errorMessage":"valueIsNull length is less than positionCount","messagePattern":"valueIsNull length is less than positionCount","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"presto-common/src/main/java/com/facebook/presto/common/block/VariableWidthBlock.java","lineNumber":90,"sourceCode":"        }\n        this.arrayOffset = arrayOffset;\n        if (positionCount < 0) {\n            throw new IllegalArgumentException(\"positionCount is negative\");\n        }\n        this.positionCount = positionCount;\n\n        if (slice == null) {\n            throw new IllegalArgumentException(\"slice is null\");\n        }\n        this.slice = slice;\n\n        if (offsets.length - arrayOffset < (positionCount + 1)) {\n            throw new IllegalArgumentException(\"offsets length is less than positionCount\");\n        }\n        this.offsets = offsets;\n\n        if (valueIsNull != null && valueIsNull.length - arrayOffset < positionCount) {\n            throw new IllegalArgumentException(\"valueIsNull length is less than positionCount\");\n        }\n        this.valueIsNull = valueIsNull;\n\n        sizeInBytes = offsets[arrayOffset + positionCount] - offsets[arrayOffset] + ((Integer.BYTES + Byte.BYTES) * (long) positionCount);\n        retainedSizeInBytes = INSTANCE_SIZE + slice.getRetainedSize() + sizeOf(valueIsNull) + sizeOf(offsets);\n    }\n\n    @Override\n    public final int getPositionOffset(int position)\n    {\n        return offsets[position + arrayOffset];\n    }\n\n    @Override\n    public int getSliceLength(int position)\n    {\n        checkReadablePosition(position);\n        return getSliceLengthUnchecked(position + arrayOffset);","sourceCodeStart":72,"sourceCodeEnd":108,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-common/src/main/java/com/facebook/presto/common/block/VariableWidthBlock.java#L72-L108","documentation":"When a VariableWidthBlock carries nullability info, the valueIsNull boolean array must have one entry per position (valueIsNull.length - arrayOffset >= positionCount). A short array cannot record null-ness for all positions, so the constructor throws IllegalArgumentException.","triggerScenarios":"Constructing VariableWidthBlock with a non-null valueIsNull array shorter than arrayOffset + positionCount; e.g. reusing a null vector from a different-sized block or from a page read with mismatched chunk sizes.","commonSituations":"Column-reader code misaligning definition/null levels with data values; hand-written blocks in tests or connectors where valueIsNull was sized without the null count.","solutions":["Size valueIsNull to at least arrayOffset + positionCount entries before construction.","Pass null only when the block genuinely has no null values; otherwise keep the array aligned with positionCount.","Audit the page-reading path for null-vector/data misalignment."],"exampleFix":"// before\nboolean[] valueIsNull = new boolean[positions - 1]; // too short\nnew VariableWidthBlock(0, positions, slice, offsets, valueIsNull);\n// after\nboolean[] valueIsNull = new boolean[positions];\nnew VariableWidthBlock(0, positions, slice, offsets, valueIsNull);","handlingStrategy":"validation","validationCode":"checkState(valueIsNull == null || valueIsNull.length - arrayOffset >= positionCount,\n    \"valueIsNull too short for %s positions\", positionCount);","typeGuard":null,"tryCatchPattern":"try {\n    new VariableWidthBlock(arrayOffset, positionCount, slice, offsets, valueIsNull);\n} catch (IllegalArgumentException e) {\n    // realign null vector with positionCount\n}","preventionTips":["Size null vectors from the same position count used for the block","Pass null only when the block has no nulls; otherwise keep arrays aligned","Audit column readers for null-vector/data chunk misalignment"],"tags":["presto","block","illegal-argument","nullability"],"backgroundTag":"block-constructor-validation","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"}