{"record":{"id":"38dded6e12d0bbea","repo":"prestodb/presto","slug":"arrayoffset-is-negative-38dded","errorCode":null,"errorMessage":"arrayOffset is negative","messagePattern":"arrayOffset is negative","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"presto-common/src/main/java/com/facebook/presto/common/block/VariableWidthBlock.java","lineNumber":71,"sourceCode":"    private final int arrayOffset;\n    private final int positionCount;\n    private final Slice slice;\n    private final int[] offsets;\n    @Nullable\n    private final boolean[] valueIsNull;\n\n    private final long retainedSizeInBytes;\n    private final long sizeInBytes;\n\n    public VariableWidthBlock(int positionCount, Slice slice, int[] offsets, Optional<boolean[]> valueIsNull)\n    {\n        this(0, positionCount, slice, offsets, valueIsNull.orElse(null));\n    }\n\n    VariableWidthBlock(int arrayOffset, int positionCount, Slice slice, int[] offsets, boolean[] valueIsNull)\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 (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) {","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-common/src/main/java/com/facebook/presto/common/block/VariableWidthBlock.java#L53-L89","documentation":"The package-private VariableWidthBlock constructor validates its invariants up front. arrayOffset is the starting index into the offsets array for this block's view; a negative value means a malformed slice view was constructed and the library throws IllegalArgumentException to fail fast rather than produce corrupt blocks.","triggerScenarios":"Constructing VariableWidthBlock (public constructor delegates to this one) with a negative arrayOffset, typically from a region() / sliced-view factory computing an offset from bad position math.","commonSituations":"Custom Block implementations or slice-view code computing region offsets incorrectly; off-by-one or negative position arithmetic when creating sub-block views.","solutions":["Fix the offset computation that produces the negative arrayOffset before constructing the block.","Clamp/validate offsets at the source of the region/slice calculation.","If using public APIs, ensure positionCount/offsets derive from a valid parent block region."],"exampleFix":"// before\nnew VariableWidthBlock(parentOffset - delta, count, slice, offsets, null); // negative\n// after\nint arrayOffset = Math.max(0, parentOffset - delta);\nnew VariableWidthBlock(arrayOffset, count, slice, offsets, null);","handlingStrategy":"validation","validationCode":"checkArgument(arrayOffset >= 0, \"arrayOffset must be >= 0, got %s\", arrayOffset);","typeGuard":null,"tryCatchPattern":"try {\n    new VariableWidthBlock(arrayOffset, positionCount, slice, offsets, valueIsNull);\n} catch (IllegalArgumentException e) {\n    // fix region-offset math upstream\n}","preventionTips":["Validate region math (base positions, offsets) before constructing block views","Use existing Block.getRegion() helpers instead of hand-computed offsets","Never construct blocks from unvalidated deserialized integers"],"tags":["presto","block","illegal-argument","constructor-validation"],"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"}