{"record":{"id":"c0b2ae4540ca616e","repo":"prestodb/presto","slug":"currentfieldindextowrite-is-not-valid","errorCode":null,"errorMessage":"currentFieldIndexToWrite is not valid","messagePattern":"currentFieldIndexToWrite is not valid","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"presto-common/src/main/java/com/facebook/presto/common/block/SingleRowBlockWriter.java","lineNumber":266,"sourceCode":"\n    @Override\n    public String toString()\n    {\n        if (!fieldBlockBuilderReturned) {\n            return format(\"SingleRowBlockWriter(%d){numFields=%d, fieldBlockBuilderReturned=false, positionCount=%d}\", hashCode(), fieldBlockBuilders.length, getPositionCount());\n        }\n        else {\n            return format(\"SingleRowBlockWriter(%d){numFields=%d, fieldBlockBuilderReturned=true}\", hashCode(), fieldBlockBuilders.length);\n        }\n    }\n\n    private void checkFieldIndexToWrite()\n    {\n        if (fieldBlockBuilderReturned) {\n            throw new IllegalStateException(\"cannot do sequential write after getFieldBlockBuilder is called\");\n        }\n        if (currentFieldIndexToWrite >= fieldBlockBuilders.length) {\n            throw new IllegalStateException(\"currentFieldIndexToWrite is not valid\");\n        }\n    }\n}\n","sourceCodeStart":248,"sourceCodeEnd":270,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-common/src/main/java/com/facebook/presto/common/block/SingleRowBlockWriter.java#L248-L270","documentation":"checkFieldIndexToWrite also validates that the sequential write cursor (currentFieldIndexToWrite) has not advanced past the number of field block builders in the row, i.e. the row has more sequential entries written than it has fields. This is an IllegalArgumentException-free IllegalStateException thrown when sequential writes overflow the row's field count.","triggerScenarios":"Performing more sequential writes (writeByte/writeShort/writeInt/writeLong/writeBytes/appendStructure) than the row has fields; e.g. appending an extra entry to a row whose type declares fewer fields.","commonSituations":"Serializer/schema mismatch: the RowType changed (column added/removed) but the encoder still writes the old number of values; miscounted fields in dynamic row construction.","solutions":["Verify the number of sequential writes matches the field count of the row type.","Regenerate or update the encoder after any schema change to the row type.","Add an assertion in the caller comparing planned field count with the writer's fieldBlockBuilders length before writing."],"exampleFix":"// before\nfor (Object v : values) { writer.appendStructure(...); } // values larger than row arity\n// after\ncheckState(values.size() == fieldCount, \"row arity mismatch\");\nfor (Object v : values) { writer.appendStructure(...); }","handlingStrategy":"validation","validationCode":"checkState(plannedFieldCount == expectedRowArity, \"sequential writes exceed row field count\");","typeGuard":null,"tryCatchPattern":"try {\n    writer.appendStructure(value);\n} catch (IllegalStateException e) {\n    // too many writes: schema/encoder mismatch, fail fast with schema info\n}","preventionTips":["Derive write count from RowType.getParameters() rather than hardcoding","Re-run encoder tests after every schema change","Assert values.size() == row arity before writing"],"tags":["presto","block-builder","illegal-state","schema-mismatch"],"backgroundTag":"row-arity-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"}