{"record":{"id":"4ee6556f8219c0ff","repo":"apache/cassandra","slug":"not-enough-bytes-to-deserialize-a-map","errorCode":null,"errorMessage":"Not enough bytes to deserialize a map","messagePattern":"Not enough bytes to deserialize a map","errorType":"exception","errorClass":"InvalidTypeException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/functions/types/TypeCodec.java","lineNumber":2516,"sourceCode":"            if (bytes == null || bytes.remaining() == 0) return newInstance(0);\n            try\n            {\n                ByteBuffer input = bytes.duplicate();\n                int n = CodecUtils.readSize(input, protocolVersion);\n                Map<K, V> m = newInstance(n);\n                for (int i = 0; i < n; i++)\n                {\n                    ByteBuffer kbb = CodecUtils.readValue(input, protocolVersion);\n                    ByteBuffer vbb = CodecUtils.readValue(input, protocolVersion);\n                    m.put(\n                    keyCodec.deserialize(kbb, protocolVersion),\n                    valueCodec.deserialize(vbb, protocolVersion));\n                }\n                return m;\n            }\n            catch (BufferUnderflowException e)\n            {\n                throw new InvalidTypeException(\"Not enough bytes to deserialize a map\", e);\n            }\n        }\n\n        /**\n         * Return a new {@link Map} instance with the given estimated size.\n         *\n         * @param size The estimated size of the collection to create.\n         * @return A new {@link Map} instance with the given estimated size.\n         */\n        protected abstract Map<K, V> newInstance(int size);\n    }\n\n    /**\n     * This codec maps a CQL {@link DataType#map(DataType, DataType) map type} to a Java {@link Map}.\n     * Implementation note: this codec returns mutable, non thread-safe {@link LinkedHashMap}\n     * instances.\n     */\n    private static class MapCodec<K, V> extends AbstractMapCodec<K, V>","sourceCodeStart":2498,"sourceCodeEnd":2534,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/functions/types/TypeCodec.java#L2498-L2534","documentation":"BufferUnderflowException-style InvalidTypeException from the map codec's deserialize: the input buffer does not contain enough bytes for the declared number of key/value pairs (size read via CodecUtils.readSize, then each entry via readValue). Truncated or corrupt serialized map data triggers it.","triggerScenarios":"Thrown at src/java/org/apache/cassandra/cql3/functions/types/TypeCodec.java:2516 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Verify the bytes were produced by the same codec/protocol version on both ends","Check for truncation of the blob (column type mismatch, manual byte manipulation)","Re-write the data from the original source instead of patching the corrupted buffer"],"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"}