apache/cassandra · error · InvalidTypeException
Invalid type for map value, expecting
Error message
Invalid type for map value, expecting %s but got %s
What it means
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.
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
Defensive patterns
Strategy: type-guard
When it happens
Trigger: Thrown at src/java/org/apache/cassandra/cql3/functions/types/TypeCodec.java:2483 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10).
Data as JSON: /api/errors/f0223e407019df27.
Report an issue: GitHub.
Appendix: source
Thrown at src/java/org/apache/cassandra/cql3/functions/types/TypeCodec.java:2483
throw new InvalidTypeException(
String.format(
"Invalid type for map key, expecting %s but got %s",
keyCodec.getJavaType(), key.getClass()),
e);
}
ByteBuffer bbv;
V v = entry.getValue();
if (v == null)
{
throw new NullPointerException("Map values cannot be null");
}
try
{
bbv = valueCodec.serialize(v, protocolVersion);
}
catch (ClassCastException e)
{
throw new InvalidTypeException(
String.format(
"Invalid type for map value, expecting %s but got %s",
valueCodec.getJavaType(), v.getClass()),
e);
}
bbs[i++] = bbk;
bbs[i++] = bbv;
}
return CodecUtils.pack(bbs, value.size(), protocolVersion);
}
@Override
public Map<K, V> deserialize(ByteBuffer bytes, ProtocolVersion protocolVersion)
{
if (bytes == null || bytes.remaining() == 0) return newInstance(0);
try
{
ByteBuffer input = bytes.duplicate();View on GitHub (pinned to 88fd0f6a0e)