{"record":{"id":"f0223e407019df27","repo":"apache/cassandra","slug":"invalid-type-for-map-value-expecting-s-but-got","errorCode":null,"errorMessage":"Invalid type for map value, expecting %s but got %s","messagePattern":"Invalid type for map value, expecting (.+?) but got (.+?)","errorType":"exception","errorClass":"InvalidTypeException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/functions/types/TypeCodec.java","lineNumber":2483,"sourceCode":"                    throw new InvalidTypeException(\n                    String.format(\n                    \"Invalid type for map key, expecting %s but got %s\",\n                    keyCodec.getJavaType(), key.getClass()),\n                    e);\n                }\n                ByteBuffer bbv;\n                V v = entry.getValue();\n                if (v == null)\n                {\n                    throw new NullPointerException(\"Map values cannot be null\");\n                }\n                try\n                {\n                    bbv = valueCodec.serialize(v, protocolVersion);\n                }\n                catch (ClassCastException e)\n                {\n                    throw new InvalidTypeException(\n                    String.format(\n                    \"Invalid type for map value, expecting %s but got %s\",\n                    valueCodec.getJavaType(), v.getClass()),\n                    e);\n                }\n                bbs[i++] = bbk;\n                bbs[i++] = bbv;\n            }\n            return CodecUtils.pack(bbs, value.size(), protocolVersion);\n        }\n\n        @Override\n        public Map<K, V> deserialize(ByteBuffer bytes, ProtocolVersion protocolVersion)\n        {\n            if (bytes == null || bytes.remaining() == 0) return newInstance(0);\n            try\n            {\n                ByteBuffer input = bytes.duplicate();","sourceCodeStart":2465,"sourceCodeEnd":2501,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/functions/types/TypeCodec.java#L2465-L2501","documentation":"InvalidTypeException from the map codec's serialize: a map value object's Java type does not match the codec's expected Java type (the message shows expected vs. actual class). It is the value-side counterpart to the key-type check just above; the failure occurs while serializing an entry whose runtime type is wrong for valueCodec.","triggerScenarios":"Thrown at src/java/org/apache/cassandra/cql3/functions/types/TypeCodec.java:2483 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Ensure map values are of the Java type bound to the CQL value type (e.g. String for text, Long for bigint)","Fix generic type parameters of the map passed to the codec/bound statement","Add an explicit value codec or conversion for the actual Java type being written"],"exampleFix":null,"handlingStrategy":"type-guard","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"}