{"record":{"id":"39c43537f556ba05","repo":"prestodb/presto","slug":"position-is-not-valid-position-39c435","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/AbstractSingleRowBlock.java","lineNumber":37,"sourceCode":"\nimport static com.facebook.presto.common.block.BlockUtil.internalPositionInRange;\n\npublic abstract class AbstractSingleRowBlock\n        implements Block\n{\n    protected final int rowIndex;\n\n    protected AbstractSingleRowBlock(int rowIndex)\n    {\n        this.rowIndex = rowIndex;\n    }\n\n    protected abstract Block getRawFieldBlock(int fieldIndex);\n\n    private void checkFieldIndex(int position)\n    {\n        if (position < 0 || position >= getPositionCount()) {\n            throw new IllegalArgumentException(\"position is not valid: \" + position);\n        }\n    }\n\n    @Override\n    public boolean isNull(int position)\n    {\n        checkFieldIndex(position);\n        return getRawFieldBlock(position).isNull(rowIndex);\n    }\n\n    @Override\n    public byte getByte(int position)\n    {\n        checkFieldIndex(position);\n        return getRawFieldBlock(position).getByte(rowIndex);\n    }\n\n    @Override","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-common/src/main/java/com/facebook/presto/common/block/AbstractSingleRowBlock.java#L19-L55","documentation":"AbstractSingleRowBlock.checkFieldIndex validates that a field index passed to accessors (isNull, getByte, getShort, getInt, getLong, getSlice) lies within [0, getPositionCount()). Out-of-range field indices throw IllegalArgumentException with the offending index included in the message.","triggerScenarios":"Calling field accessors with index < 0 or >= the number of row fields, e.g. from a RowType field ordinal computed against a different row type, or evaluating a field reference against a mismatched block.","commonSituations":"Expression compiler bugs mapping dereference ordinals to wrong row types; schema drift where the query plan's row type has more fields than the block's row type (e.g. after connector metadata changes).","solutions":["Verify the field ordinal comes from the same RowType used to build the single-row block.","Fix plan/schema mismatches: clear caches or restart after connector metadata changes so blocks and their types agree.","Add bounds checks against rowType.getFields().size() in custom evaluation code."],"exampleFix":"// before\nint field = fieldNameToIndex.get(\"new_column\"); // not present in block's row type\nrowBlock.getLong(field);\n// after\nif (field < 0 || field >= rowBlock.getPositionCount()) {\n    throw new IllegalStateException(\"field ordinal out of range for row type\");\n}\nrowBlock.getLong(field);","handlingStrategy":"type-guard","validationCode":"static boolean isValidFieldIndex(Block singleRowBlock, int fieldIndex) {\n    return fieldIndex >= 0 && fieldIndex < singleRowBlock.getPositionCount();\n}","typeGuard":"static boolean hasField(RowType rowType, int ordinal) {\n    return ordinal >= 0 && ordinal < rowType.getFields().size();\n}","tryCatchPattern":"try {\n    long v = rowBlock.getLong(fieldIndex);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage() != null && e.getMessage().contains(\"position is not valid\")) {\n        throw new IndexOutOfBoundsException(\"field ordinal out of range: \" + e.getMessage());\n    }\n    throw e;\n}","preventionTips":["Resolve field ordinals from the same RowType instance used to create the block.","Handle connector metadata changes by invalidating cached plans/blocks.","Check ordinal bounds in generated expression code before dereference."],"tags":["presto","block","row-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"}