apache/cassandra · error · NullPointerException
Collection elements cannot be null
Error message
Collection elements cannot be null
What it means
NullPointerException from the list/set codec's serialize: one of the elements in the Java collection to serialize is null. CQL lists and sets do not permit null elements (unlike the collection itself, which may be null), so serialization aborts at the offending element.
Solutions
- Filter null elements out of the collection before serializing
- Represent absent elements by omitting them, or model nullability with a map (maps permit null-typed values via sentinels) or a UDT
- Validate client-side data construction to never insert nulls into list/set fields
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at src/java/org/apache/cassandra/cql3/functions/types/TypeCodec.java:2123 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/5c0008c40f082ce9.
Report an issue: GitHub.
Appendix: source
Thrown at src/java/org/apache/cassandra/cql3/functions/types/TypeCodec.java:2123
super(cqlType, javaType);
checkArgument(
cqlType.getName() == Name.LIST || cqlType.getName() == Name.SET,
"Expecting list or set type, got %s",
cqlType);
this.eltCodec = eltCodec;
}
@Override
public ByteBuffer serialize(C value, ProtocolVersion protocolVersion)
{
if (value == null) return null;
int i = 0;
ByteBuffer[] bbs = new ByteBuffer[value.size()];
for (E elt : value)
{
if (elt == null)
{
throw new NullPointerException("Collection elements cannot be null");
}
ByteBuffer bb;
try
{
bb = eltCodec.serialize(elt, protocolVersion);
}
catch (ClassCastException e)
{
throw new InvalidTypeException(
String.format(
"Invalid type for %s element, expecting %s but got %s",
cqlType, eltCodec.getJavaType(), elt.getClass()),
e);
}
bbs[i++] = bb;
}
return CodecUtils.pack(bbs, value.size(), protocolVersion);
}View on GitHub (pinned to 88fd0f6a0e)