{"record":{"id":"9276fa889b059f18","repo":"prestodb/presto","slug":"position-is-not-valid-position","errorCode":null,"errorMessage":"position is not valid: \" + position","messagePattern":"position is not valid: \" \\+ position","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"presto-common/src/main/java/com/facebook/presto/common/block/AbstractSingleMapBlock.java","lineNumber":34,"sourceCode":"\nimport io.airlift.slice.Slice;\nimport io.airlift.slice.SliceOutput;\n\nimport static com.facebook.presto.common.block.BlockUtil.internalPositionInRange;\n\npublic abstract class AbstractSingleMapBlock\n        implements Block\n{\n    abstract int getOffset();\n\n    abstract Block getRawKeyBlock();\n\n    abstract Block getRawValueBlock();\n\n    private int getAbsolutePosition(int position)\n    {\n        if (position < 0 || position >= getPositionCount()) {\n            throw new IllegalArgumentException(\"position is not valid: \" + position);\n        }\n        return position + getOffset();\n    }\n\n    @Override\n    public boolean isNull(int position)\n    {\n        position = getAbsolutePosition(position);\n        if (position % 2 == 0) {\n            if (getRawKeyBlock().isNull(position / 2)) {\n                throw new IllegalStateException(\"Map key is null at position: \" + position);\n            }\n            return false;\n        }\n        else {\n            return getRawValueBlock().isNull(position / 2);\n        }\n    }","sourceCodeStart":16,"sourceCodeEnd":52,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-common/src/main/java/com/facebook/presto/common/block/AbstractSingleMapBlock.java#L16-L52","documentation":"AbstractSingleMapBlock.getAbsolutePosition maps a caller-supplied position into the underlying key/value block position space. If position is negative or >= getPositionCount() (which is 2 for a single-entry map: one key, one value), it throws IllegalArgumentException including the offending position value.","triggerScenarios":"Calling isNull/getByte/getShort/getInt/getLong/getSlice on a single-map block with a position outside [0, 2); typically from passing array- or row-style positions, or raw key-block positions.","commonSituations":"Custom accessors for map entries treating the block as a general block with many positions; expression evaluation bugs reading key/value at wrong indices.","solutions":["Only pass 0 (key) or 1 (value) positions to a single-map block, or use typed accessor APIs.","Fix callers to map logical key/value indices to the 0/1 positions of the single-map block.","Add bounds checks in the calling operator before invoking raw block getters."],"exampleFix":"// before\nint rawPos = mapBlock.getPositionCount(); // e.g. out-of-range index\nmapBlock.getInt(rawPos);\n// after\nint rawPos = Math.min(entryIndex, mapBlock.getPositionCount() - 1);\ncheckArgument(rawPos >= 0, \"entry index out of range\");\nmapBlock.getInt(rawPos);","handlingStrategy":"type-guard","validationCode":"static boolean isValidSingleMapPosition(Block mapBlock, int position) {\n    return position >= 0 && position < mapBlock.getPositionCount(); // 0 = key, 1 = value\n}","typeGuard":"static boolean canAccessEntry(Block singleMapBlock, int position) {\n    return position == 0 || position == 1;\n}","tryCatchPattern":"try {\n    long v = mapBlock.getLong(position);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage() != null && e.getMessage().contains(\"position is not valid\")) {\n        throw new IndexOutOfBoundsException(\"single map position out of range: \" + e.getMessage());\n    }\n    throw e;\n}","preventionTips":["Remember single-map block positions are only 0 (key) and 1 (value).","Use higher-level map access APIs (MapType.getObject) instead of raw positions.","Assert position space before crossing from array/map blocks into single-map blocks."],"tags":["presto","block","map-block","bounds-check","illegal-argument"],"backgroundTag":"position-out-of-bounds","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"}