apache/cassandra · error · MarshalException

Not enough bytes to read comparator name of component %s

Error message

Not enough bytes to read comparator name of component %s

What it means

In DynamicCompositeType.validateComparator(), when the header short's high bit (0x8000) is clear, the remaining header bits are a length and the comparator class name follows as bytes. If the buffer holds fewer bytes than the header's declared length, the value is malformed and this MarshalException is thrown. It signals truncated or wrongly-encoded composite component data.

Source

Thrown at src/java/org/apache/cassandra/db/marshal/DynamicCompositeType.java:492

        return result;
    }

    protected ParsedComparator parseComparator(int i, String part)
    {
        return new DynamicParsedComparator(part);
    }

    protected <V> AbstractType<?> validateComparator(int i, V input, ValueAccessor<V> accessor, int offset) throws MarshalException
    {
        AbstractType<?> comparator = null;
        if (accessor.sizeFromOffset(input, offset) < 2)
            throw new MarshalException("Not enough bytes to header of the comparator part of component " + i);
        int header = accessor.getShort(input, offset);
        offset += TypeSizes.SHORT_SIZE;
        if ((header & 0x8000) == 0)
        {
            if (accessor.sizeFromOffset(input, offset) < header)
                throw new MarshalException("Not enough bytes to read comparator name of component " + i);

            V value = accessor.slice(input, offset, header);
            String valueStr = null;
            try
            {
                valueStr = accessor.toString(value);
                comparator = TypeParser.parse(valueStr);
            }
            catch (CharacterCodingException ce)
            {
                // ByteBufferUtil.string failed.
                // Log it here and we'll further throw an exception below since comparator == null
                logger.error("Failed when decoding the byte buffer in ByteBufferUtil.string()", ce);
            }
            catch (Exception e)
            {
                // parse failed.
                // Log it here and we'll further throw an exception below since comparator == null

View on GitHub (pinned to 88fd0f6a0e)

Solutions

  1. Regenerate the value using the type's own decompose/build APIs so lengths match the actual name bytes
  2. Re-read from a healthy replica; run scrub/repair if the stored bytes are corrupt
  3. Audit any custom serializer code that writes the comparator-name length to ensure it uses the encoded byte length
Defensive patterns

Strategy: try-catch

Try / catch

try { type.validate(buffer); } catch (MarshalException e) { log.error("Corrupt composite component bytes", e); }

Prevention

When it happens

Trigger: A composite component declares a comparator-name length (e.g. 20 bytes for 'org.apache.cassandra...') but the buffer ends before those bytes, during validation of values read from disk or received in a mutation.

Common situations: Hand-crafted composite buffers with wrong length fields; partial writes/corruption; tooling that slices composite values at incorrect offsets.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10). Data as JSON: /api/errors/60f700a3bf4f99c5. Report an issue: GitHub.