{"record":{"id":"4f950e1474168fc0","repo":"prestodb/presto","slug":"invalid-positions-array-size-d-actual-position-c","errorCode":null,"errorMessage":"Invalid positions array size %d, actual position count is %d","messagePattern":"Invalid positions array size (.+?), actual position count is (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"presto-common/src/main/java/com/facebook/presto/common/block/BlockUtil.java","lineNumber":68,"sourceCode":"    static void checkArrayRange(boolean[] array, int offset, int length)\n    {\n        requireNonNull(array, \"array is null\");\n        if (offset < 0 || length < 0 || offset + length > array.length) {\n            throw new IndexOutOfBoundsException(format(\"Invalid offset %s and length %s in array with %s elements\", offset, length, array.length));\n        }\n    }\n\n    static void checkValidRegion(int positionCount, int positionOffset, int length)\n    {\n        if (positionOffset < 0 || length < 0 || positionOffset + length > positionCount) {\n            throw new IndexOutOfBoundsException(format(\"Invalid position %s and length %s in block with %s positions\", positionOffset, length, positionCount));\n        }\n    }\n\n    static void checkValidPositions(boolean[] positions, int positionCount)\n    {\n        if (positions.length != positionCount) {\n            throw new IllegalArgumentException(format(\"Invalid positions array size %d, actual position count is %d\", positions.length, positionCount));\n        }\n    }\n\n    static void checkValidPosition(int position, int positionCount)\n    {\n        if (position < 0 || position >= positionCount) {\n            throw new IllegalArgumentException(format(\"Invalid position %s in block with %s positions\", position, positionCount));\n        }\n    }\n\n    static void checkValidSliceRange(int sourceIndex, int length)\n    {\n        //sourceIndex + length can overflow integer range\n        if (sourceIndex > MAX_ARRAY_SIZE - length) {\n            throw new SliceTooLargeException(format(\"Cannot allocate slice larger than %d bytes\", MAX_ARRAY_SIZE));\n        }\n    }\n","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-common/src/main/java/com/facebook/presto/common/block/BlockUtil.java#L50-L86","documentation":"BlockUtil.checkValidPositions requires a boolean[] selection mask to have exactly one entry per block position. It throws IllegalArgumentException when positions.length differs from the block's positionCount, because a mismatched mask would silently select or skip the wrong rows.","triggerScenarios":"Calling Block.getPositions with a boolean[] built against a different (stale, shorter, or longer) positionCount than the target block — e.g. reusing a mask from a previous page.","commonSituations":"Filter operators caching selection masks across pages of differing sizes; vectorized engines reusing buffers after a block resize; custom operators building masks from upstream column of mismatched cardinality.","solutions":["Rebuild the boolean[] mask for the current block's getPositionCount() instead of reusing a stale one","Assert positions.length == positionCount at the mask-construction site","Catch IllegalArgumentException to report a mask-vs-block cardinality mismatch with both sizes"],"exampleFix":"// before\nblock.getPositions(cachedMask, positionCount, mask);\n// after\nboolean[] mask = new boolean[block.getPositionCount()];\nblock.getPositions(mask, block.getPositionCount(), mask);","handlingStrategy":"validation","validationCode":"if (positions.length != block.getPositionCount()) {\n    positions = new boolean[block.getPositionCount()];\n}","typeGuard":"boolean isValidPositionsMask(boolean[] positions, int positionCount) {\n    return positions != null && positions.length == positionCount;\n}","tryCatchPattern":"try {\n    result = block.getPositions(positions, offset, size);\n} catch (IllegalArgumentException e) {\n    throw new PrestoException(GENERIC_INTERNAL_ERROR, \"positions mask size mismatch\", e);\n}","preventionTips":["Rebuild selection masks per page instead of caching across pages","Size masks from block.getPositionCount() at use time","Unit-test operators with pages of varying position counts"],"tags":["java","presto","illegal-argument","block-positions"],"backgroundTag":"argument-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"}