{"record":{"id":"ca67fbf6e2cee9a4","repo":"apache/cassandra","slug":"native-protocol-version-d-supports-only-elements","errorCode":null,"errorMessage":"Native protocol version %d supports only elements with size up to 65535 bytes - but element size is %d bytes","messagePattern":"Native protocol version (.+?) supports only elements with size up to 65535 bytes - but element size is (.+?) bytes","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/functions/types/CodecUtils.java","lineNumber":251,"sourceCode":"            case V3:\n            case V4:\n            case V5:\n            case V6:\n                return 4;\n            default:\n                throw new IllegalArgumentException(String.valueOf(version));\n        }\n    }\n\n    private static int sizeOfValue(ByteBuffer value, ProtocolVersion version)\n    {\n        switch (version)\n        {\n            case V1:\n            case V2:\n                int elemSize = value.remaining();\n                if (elemSize > 65535)\n                    throw new IllegalArgumentException(\n                    String.format(\n                    \"Native protocol version %d supports only elements with size up to 65535 bytes - but element size is %d bytes\",\n                    version.asInt(), elemSize));\n                return 2 + elemSize;\n            case V3:\n            case V4:\n            case V5:\n            case V6:\n                return value == null ? 4 : 4 + value.remaining();\n            default:\n                throw new IllegalArgumentException(String.valueOf(version));\n        }\n    }\n\n    private static int getUnsignedShort(ByteBuffer bb)\n    {\n        int length = (bb.get() & 0xFF) << 8;\n        return length | (bb.get() & 0xFF);","sourceCodeStart":233,"sourceCodeEnd":269,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/functions/types/CodecUtils.java#L233-L269","documentation":"In native protocol V1/V2, each collection element is length-prefixed with a 16-bit size, so no single element may exceed 65535 bytes. CodecUtils.sizeOfValue (used by elemSize while computing the serialized size of a collection) enforces this and throws IllegalArgumentException when an element's ByteBuffer exceeds that limit.","triggerScenarios":"Encoding a collection (list/set/map) containing one element larger than 64KB — e.g. a list<blob> holding a 100KB blob — while executing on protocol V1 or V2.","commonSituations":"Legacy V1/V2 protocol configs combined with large text/blob collection entries; storing big documents or images inside collection elements; compress-then-insert flows producing oversized elements.","solutions":["Move to native protocol V3+ where element sizes use 32-bit prefixes","Compress or truncate the large element so each is under 65535 bytes","Store large values in a dedicated column/table (possibly with a pointer in the collection) instead of inside collections"],"exampleFix":"// before\ncluster.builder().withProtocolVersion(ProtocolVersion.V1); // 64KB element cap\n// after\ncluster.builder().withProtocolVersion(ProtocolVersion.V4);","handlingStrategy":"validation","validationCode":"for (ByteBuffer v : elements) {\n    if (v.remaining() > 65535 && protocolVersion.compareTo(ProtocolVersion.V3) < 0) {\n        throw new IllegalArgumentException(\"element exceeds 64KB on V1/V2 protocol\");\n    }\n}","typeGuard":null,"tryCatchPattern":"try {\n    session.execute(boundStatement);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().contains(\"65535 bytes\")) {\n        // compress or relocate the oversized element, then retry\n    }\n}","preventionTips":["Use protocol V3+ where element sizes are 32-bit","Enforce a max element size at ingestion for blob/text collection columns","Store large payloads outside collections and reference them by key"],"tags":["java-driver","serialization","protocol-limit"],"backgroundTag":"payload-too-large","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"}