apache/cassandra · error · org.apache.cassandra.transport.ProtocolException

Invalid value ' ' for

Error message

Invalid value '%s' for %s

What it means

CBUtil.readEnumValue decodes a string from the frame and maps it to a Java enum constant (upper-cased first). If no constant matches, it throws ProtocolException naming the value and the enum type. Used for protocol strings like consistency levels, event types, or opcodes.

Solutions

  1. Send a valid enum value as defined by the negotiated protocol version
  2. Align driver and server versions so the client doesn't emit values the server doesn't know
  3. Check the exact expected spelling in the CQL native protocol spec for the field
  4. If hand-writing frames, upper-case and match enum names exactly

Example fix

// before
frame.writeUTF8String("quourm");
// after
frame.writeUTF8String("QUORUM");
Defensive patterns

Strategy: validation

Validate before calling

Set<String> allowed = Arrays.stream(ConsistencyLevel.values()).map(Enum::name).collect(Collectors.toSet());
if (!allowed.contains(value.toUpperCase(Locale.ROOT))) throw new IllegalArgumentException("Invalid consistency: " + value);

Try / catch

try { session.execute(stmt.setConsistencyLevel(cl)); } catch (ProtocolException e) { if (e.getMessage().startsWith("Invalid value '")) { fallbackToDefaultConsistency(); } else throw e; }

Prevention

When it happens

Trigger: A client sends a string field that must map to an enum (e.g., ConsistencyLevel, EventType) but the value is misspelled, wrongly cased beyond case-insensitive matching, or from a newer protocol version than the server supports.

Common situations: Newer driver sending enum values unknown to an older server; hand-rolled clients sending lowercase-with-typos or wrong value names; version skew after upgrades.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


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

Appendix: source

Thrown at src/java/org/apache/cassandra/transport/CBUtil.java:314

    {
        cb.writeShort(consistency.code);
    }

    public static int sizeOfConsistencyLevel(ConsistencyLevel consistency)
    {
        return 2;
    }

    public static <T extends Enum<T>> T readEnumValue(Class<T> enumType, ByteBuf cb)
    {
        String value = CBUtil.readString(cb);
        try
        {
            return Enum.valueOf(enumType, toUpperCaseLocalized(value));
        }
        catch (IllegalArgumentException e)
        {
            throw new ProtocolException(String.format("Invalid value '%s' for %s", value, enumType.getSimpleName()));
        }
    }

    public static <T extends Enum<T>> void writeEnumValue(T enumValue, ByteBuf cb)
    {
        // UTF-8 (non-ascii) literals can be used for as a valid identifier in Java. It is possible for an enum to be named using those characters.
        // There is no such occurence in the code base.
        writeAsciiString(enumValue.toString(), cb);
    }

    public static <T extends Enum<T>> int sizeOfEnumValue(T enumValue)
    {
        return sizeOfAsciiString(enumValue.toString());
    }

    public static UUID readUUID(ByteBuf cb)
    {
        ByteBuffer buffer = cb.nioBuffer(cb.readerIndex(), UUID_SIZE);

View on GitHub (pinned to 88fd0f6a0e)