{"record":{"id":"a1be2a17db6fee1e","repo":"apache/cassandra","slug":"too-many-bytes-for-comparator","errorCode":null,"errorMessage":"Too many bytes for comparator","messagePattern":"Too many bytes for comparator","errorType":"validation","errorClass":"MarshalException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/db/marshal/CompositeType.java","lineNumber":305,"sourceCode":"            V decoded = type.fromComparableBytes(accessor,\n                                                 ByteSourceInverse.nextComponentSource(comparableBytes, separator),\n                                                 version);\n            buffers[i++] = decoded;\n\n            lastEoc = ByteSourceInverse.getSignedByte(ByteSourceInverse.nextComponentSource(comparableBytes));\n        }\n        return build(accessor, isStatic, Arrays.copyOf(buffers, i), lastEoc);\n    }\n\n    protected ParsedComparator parseComparator(int i, String part)\n    {\n        return new StaticParsedComparator(types.get(i), part);\n    }\n\n    protected <V> AbstractType<?> validateComparator(int i, V value, ValueAccessor<V> accessor, int offset) throws MarshalException\n    {\n        if (i >= types.size())\n            throw new MarshalException(\"Too many bytes for comparator\");\n        return types.get(i);\n    }\n\n    protected <V> int getComparatorSize(int i, V value, ValueAccessor<V> accessor, int offset)\n    {\n        return 0;\n    }\n\n    public ByteBuffer decompose(Object... objects)\n    {\n        assert objects.length == types.size() : String.format(\"Expected length %d but given %d\", types.size(), objects.length);\n\n        ByteBuffer[] serialized = new ByteBuffer[objects.length];\n        for (int i = 0; i < objects.length; i++)\n        {\n            ByteBuffer buffer = ((AbstractType) types.get(i)).decompose(objects[i]);\n            serialized[i] = buffer;\n        }","sourceCodeStart":287,"sourceCodeEnd":323,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/db/marshal/CompositeType.java#L287-L323","documentation":"CompositeType's internal validateComparator is asked for the type of component i; when i is beyond the configured type list it throws this MarshalException. It means the serialized composite contains more components than the type definition allows, i.e. the data does not fit the schema.","triggerScenarios":"Validating a composite value whose serialized form has more encoded components than types.size(); validation triggered on read/write of rows written under an older, wider comparator schema.","commonSituations":"Comparator redefinition after data was written; corruption or truncation of type metadata; manual SSTable manipulation.","solutions":["Fix the schema so the type list covers all serialized components","Rewrite/scrub SSTables that contain composites written under the old schema","Inspect the offending values with sstabledump to confirm the component count","Restore schema from backup if the change was accidental"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"boolean fitsSchema(CompositeType ct, ByteBuffer composite) { int count = 0; /* decode component count and compare to ct.types.size() */ return count <= ct.types.size(); }","typeGuard":null,"tryCatchPattern":"try { compositeType.validate(value); } catch (MarshalException e) { /* handle 'Too many bytes for comparator' as schema mismatch */ }","preventionTips":["Avoid in-place changes to clustering/comparator types","Validate legacy data after migrations with scrub or targeted reads","Document comparator definitions alongside snapshot backups"],"tags":["marshal","composite","validation"],"backgroundTag":"schema-validation-failed","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"}