{"record":{"id":"b39bccaadc390f56","repo":"apache/cassandra","slug":"tuple-value-contains-too-many-fields-expected-s","errorCode":null,"errorMessage":"Tuple value contains too many fields (expected %s, got %s)","messagePattern":"Tuple value contains too many fields \\(expected (.+?), got (.+?)\\)","errorType":"validation","errorClass":"MarshalException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/db/marshal/TupleType.java","lineNumber":408,"sourceCode":"        return pack(Arrays.asList(components));\n    }\n\n    @Override\n    public List<ByteBuffer> filterSortAndValidateElements(List<ByteBuffer> buffers)\n    {\n        return filterSortAndValidateElements(buffers, ByteBufferUtil.UNSET_BYTE_BUFFER, ByteBufferAccessor.instance);\n    }\n\n    @Override\n    public List<byte[]> filterSortAndValidateElementsFromArrays(List<byte[]> buffers)\n    {\n        return filterSortAndValidateElements(buffers, ByteArrayUtil.UNSET_BYTE_ARRAY, ByteArrayAccessor.instance);\n    }\n\n    private <T> List<T> filterSortAndValidateElements(List<T> buffers, T unsetValue, ValueAccessor<T> valueAccessor)\n    {\n        if (buffers.size() > size())\n            throw new MarshalException(String.format(\"Tuple value contains too many fields (expected %s, got %s)\", size(), buffers.size()));\n\n        for (int i = 0; i < buffers.size(); i++)\n        {\n            // Since A tuple value is always written in its entirety Cassandra can't preserve a pre-existing value by 'not setting' the new value. Reject the query.\n            T buffer = buffers.get(i);\n            if (buffer == null)\n                continue;\n            if (buffer == unsetValue)\n                throw new InvalidRequestException(String.format(\"Invalid unset value for tuple field number %d\", i));\n            type(i).validate(buffer, valueAccessor);\n        }\n\n        return buffers;\n    }\n\n    @Override\n    public <V> String getString(V input, ValueAccessor<V> accessor)\n    {","sourceCodeStart":390,"sourceCodeEnd":426,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/db/marshal/TupleType.java#L390-L426","documentation":"TupleType.filterSortAndValidateElements validates a list of field buffers before binding them into a tuple value. If more field values are supplied than the tuple type declares (size()), it throws this MarshalException. Tuples in Cassandra have a fixed arity, so extra values cannot be stored.","triggerScenarios":"Binding an INSERT/UPDATE with more literal elements than the tuple column's declared types (e.g. tuple<int,int> given 3 elements); calling bind/fromString-related paths with an oversized field list.","commonSituations":"Application builds the tuple programmatically from a variable-length list and appends extra elements; schema altered the tuple to fewer fields but client code still sends the old width.","solutions":["Truncate or fix the value list to match the declared tuple arity","Check the table schema (DESCRIBE / system_schema.columns) for the current tuple definition","If the tuple needs more fields, ALTER the column type first, then insert","Validate list length in application code before binding the statement"],"exampleFix":"// before\ntupleType.filterSortAndValidateElements(fields); // fields.size() may exceed arity\n// after\nif (fields.size() > tupleType.size())\n    fields = fields.subList(0, tupleType.size());\ntupleType.filterSortAndValidateElements(fields);","handlingStrategy":"validation","validationCode":"if (fields.size() > tupleType.size())\n    throw new IllegalArgumentException(\"expected at most \" + tupleType.size() + \" fields, got \" + fields.size());","typeGuard":null,"tryCatchPattern":"try {\n    tupleType.bind(fields);\n} catch (MarshalException e) {\n    throw new IllegalArgumentException(\"tuple arity mismatch: \" + e.getMessage());\n}","preventionTips":["Validate field-list length against tupleType.size() before binding","Read the live schema instead of hard-coding tuple arity","Re-check client code after any ALTER of the tuple type"],"tags":["tuple","validation","cql"],"backgroundTag":"invalid-argument-value","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}