apache/cassandra · error · InvalidTypeException

Not enough bytes to deserialize a UDT

Error message

Not enough bytes to deserialize a UDT

What it means

InvalidTypeException from the UDT codec's deserialize: the input buffer ended before all declared fields' values could be read (each field is a 4-byte length plus that many bytes). It signals truncated/corrupt UDT serialization — the loop breaks on exhausted input, and any short read mid-field throws.

Solutions

  1. Ensure producer and consumer agree on the UDT definition and protocol version
  2. Avoid truncating or hand-editing the serialized blob
  3. Reserialize the value from its structured form if the bytes are known to be corrupt
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at src/java/org/apache/cassandra/cql3/functions/types/TypeCodec.java:2624 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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

Appendix: source

Thrown at src/java/org/apache/cassandra/cql3/functions/types/TypeCodec.java:2624

            // empty byte buffers will result in empty values
            try
            {
                ByteBuffer input = bytes.duplicate();
                T value = newInstance();
                for (UserType.Field field : definition)
                {
                    if (!input.hasRemaining()) break;
                    int n = input.getInt();
                    ByteBuffer element = n < 0 ? null : CodecUtils.readBytes(input, n);
                    value =
                    deserializeAndSetField(
                    element, value, Metadata.quoteIfNecessary(field.getName()), protocolVersion);
                }
                return value;
            }
            catch (BufferUnderflowException e)
            {
                throw new InvalidTypeException("Not enough bytes to deserialize a UDT", e);
            }
        }

        @Override
        public String format(T value)
        {
            if (value == null) return "NULL";
            StringBuilder sb = new StringBuilder("{");
            int i = 0;
            for (UserType.Field field : definition)
            {
                if (i > 0) sb.append(',');
                sb.append(Metadata.quoteIfNecessary(field.getName()));
                sb.append(':');
                sb.append(formatField(value, Metadata.quoteIfNecessary(field.getName())));
                i += 1;
            }
            sb.append('}');

View on GitHub (pinned to 88fd0f6a0e)