{"record":{"id":"3d6011661d070c2b","repo":"apache/cassandra","slug":"not-enough-bytes-to-deserialize-a-udt","errorCode":null,"errorMessage":"Not enough bytes to deserialize a UDT","messagePattern":"Not enough bytes to deserialize a UDT","errorType":"exception","errorClass":"InvalidTypeException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/functions/types/TypeCodec.java","lineNumber":2624,"sourceCode":"            // empty byte buffers will result in empty values\n            try\n            {\n                ByteBuffer input = bytes.duplicate();\n                T value = newInstance();\n                for (UserType.Field field : definition)\n                {\n                    if (!input.hasRemaining()) break;\n                    int n = input.getInt();\n                    ByteBuffer element = n < 0 ? null : CodecUtils.readBytes(input, n);\n                    value =\n                    deserializeAndSetField(\n                    element, value, Metadata.quoteIfNecessary(field.getName()), protocolVersion);\n                }\n                return value;\n            }\n            catch (BufferUnderflowException e)\n            {\n                throw new InvalidTypeException(\"Not enough bytes to deserialize a UDT\", e);\n            }\n        }\n\n        @Override\n        public String format(T value)\n        {\n            if (value == null) return \"NULL\";\n            StringBuilder sb = new StringBuilder(\"{\");\n            int i = 0;\n            for (UserType.Field field : definition)\n            {\n                if (i > 0) sb.append(',');\n                sb.append(Metadata.quoteIfNecessary(field.getName()));\n                sb.append(':');\n                sb.append(formatField(value, Metadata.quoteIfNecessary(field.getName())));\n                i += 1;\n            }\n            sb.append('}');","sourceCodeStart":2606,"sourceCodeEnd":2642,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/functions/types/TypeCodec.java#L2606-L2642","documentation":"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.","triggerScenarios":"Thrown at src/java/org/apache/cassandra/cql3/functions/types/TypeCodec.java:2624 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Ensure producer and consumer agree on the UDT definition and protocol version","Avoid truncating or hand-editing the serialized blob","Reserialize the value from its structured form if the bytes are known to be corrupt"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"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"}