{"record":{"id":"ecd8bea5456d8510","repo":"apache/cassandra","slug":"invalid-value-s-for-s","errorCode":null,"errorMessage":"Invalid value '%s' for %s","messagePattern":"Invalid value '(.+?)' for (.+?)","errorType":"exception","errorClass":"org.apache.cassandra.transport.ProtocolException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/transport/CBUtil.java","lineNumber":314,"sourceCode":"    {\n        cb.writeShort(consistency.code);\n    }\n\n    public static int sizeOfConsistencyLevel(ConsistencyLevel consistency)\n    {\n        return 2;\n    }\n\n    public static <T extends Enum<T>> T readEnumValue(Class<T> enumType, ByteBuf cb)\n    {\n        String value = CBUtil.readString(cb);\n        try\n        {\n            return Enum.valueOf(enumType, toUpperCaseLocalized(value));\n        }\n        catch (IllegalArgumentException e)\n        {\n            throw new ProtocolException(String.format(\"Invalid value '%s' for %s\", value, enumType.getSimpleName()));\n        }\n    }\n\n    public static <T extends Enum<T>> void writeEnumValue(T enumValue, ByteBuf cb)\n    {\n        // 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.\n        // There is no such occurence in the code base.\n        writeAsciiString(enumValue.toString(), cb);\n    }\n\n    public static <T extends Enum<T>> int sizeOfEnumValue(T enumValue)\n    {\n        return sizeOfAsciiString(enumValue.toString());\n    }\n\n    public static UUID readUUID(ByteBuf cb)\n    {\n        ByteBuffer buffer = cb.nioBuffer(cb.readerIndex(), UUID_SIZE);","sourceCodeStart":296,"sourceCodeEnd":332,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/transport/CBUtil.java#L296-L332","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Send a valid enum value as defined by the negotiated protocol version","Align driver and server versions so the client doesn't emit values the server doesn't know","Check the exact expected spelling in the CQL native protocol spec for the field","If hand-writing frames, upper-case and match enum names exactly"],"exampleFix":"// before\nframe.writeUTF8String(\"quourm\");\n// after\nframe.writeUTF8String(\"QUORUM\");","handlingStrategy":"validation","validationCode":"Set<String> allowed = Arrays.stream(ConsistencyLevel.values()).map(Enum::name).collect(Collectors.toSet());\nif (!allowed.contains(value.toUpperCase(Locale.ROOT))) throw new IllegalArgumentException(\"Invalid consistency: \" + value);","typeGuard":null,"tryCatchPattern":"try { session.execute(stmt.setConsistencyLevel(cl)); } catch (ProtocolException e) { if (e.getMessage().startsWith(\"Invalid value '\")) { fallbackToDefaultConsistency(); } else throw e; }","preventionTips":["Use driver enums (ConsistencyLevel) instead of raw strings","Keep driver and server versions aligned before using new enum values","Validate user-supplied consistency/event strings against the protocol spec"],"tags":["cql-protocol","enum","validation"],"backgroundTag":"invalid-enum-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"}