{"record":{"id":"234a06accdfb959e","repo":"apache/cassandra","slug":"tuple-contains-extra-items-expected-s-s","errorCode":null,"errorMessage":"Tuple contains extra items (expected %s): %s","messagePattern":"Tuple contains extra items \\(expected (.+?)\\): (.+?)","errorType":"validation","errorClass":"MarshalException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/db/marshal/TupleType.java","lineNumber":501,"sourceCode":"            }\n        }\n        return pack(fields);\n    }\n\n    @Override\n    public Term fromJSONObject(Object parsed) throws MarshalException\n    {\n        if (parsed instanceof String)\n            parsed = JsonUtils.decodeJson((String) parsed);\n\n        if (!(parsed instanceof List))\n            throw new MarshalException(String.format(\n                    \"Expected a list representation of a tuple, but got a %s: %s\", parsed.getClass().getSimpleName(), parsed));\n\n        List<?> list = (List<?>) parsed;\n\n        if (list.size() > types.size())\n            throw new MarshalException(String.format(\"Tuple contains extra items (expected %s): %s\", types.size(), parsed));\n        else if (types.size() > list.size())\n            throw new MarshalException(String.format(\"Tuple is missing items (expected %s): %s\", types.size(), parsed));\n\n        List<Term> terms = new ArrayList<>(list.size());\n        Iterator<AbstractType<?>> typeIterator = types.iterator();\n        for (Object element : list)\n        {\n            if (element == null)\n            {\n                typeIterator.next();\n                terms.add(Constants.NULL_VALUE);\n            }\n            else\n            {\n                terms.add(typeIterator.next().fromJSONObject(element));\n            }\n        }\n","sourceCodeStart":483,"sourceCodeEnd":519,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/db/marshal/TupleType.java#L483-L519","documentation":"In TupleType.fromJSONObject, after confirming the JSON is a list, the list's length is compared with the number of declared field types. If the list has more elements than the tuple type declares, this MarshalException is thrown. Tuples are fixed-arity, so extra JSON items are rejected.","triggerScenarios":"INSERT JSON with an array longer than the tuple arity, e.g. tuple<int,int> given [1,2,3]; calling fromJSONObject with a hand-built list of extra elements.","commonSituations":"Schema changed the tuple to fewer fields while the application still sends the old width; accidental comma/element duplication in generated JSON.","solutions":["Trim the JSON array to exactly the declared arity","Re-check the table schema for the tuple definition","ALTER the tuple type first if more fields are genuinely needed","Add payload validation on the client before INSERT JSON"],"exampleFix":"// before: tuple<int,int> via INSERT JSON\n{\"t\": [1, 2, 3]}\n// after\n{\"t\": [1, 2]}","handlingStrategy":"validation","validationCode":"if (((List<?>) parsed).size() > types.size()) throw new IllegalArgumentException(\"JSON tuple has extra items\");","typeGuard":null,"tryCatchPattern":"try {\n    tupleType.fromJSONObject(parsed);\n} catch (MarshalException e) {\n    throw new IllegalArgumentException(\"tuple JSON arity mismatch: \" + e.getMessage());\n}","preventionTips":["Check array length against the tuple arity before insert","Regenerate payloads after any ALTER affecting the tuple","Keep client schema metadata up to date"],"tags":["json","tuple","validation"],"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-17T15:17:12.973Z"}