apache/cassandra · error · MarshalException
null is not supported inside collections
Error message
null is not supported inside collections
What it means
filterSortAndValidateElements checks each serialized element buffer of a list before it is stored. Cassandra forbids null elements inside collections; a null ByteBuffer triggers MarshalException with this message.
Source
Thrown at src/java/org/apache/cassandra/db/marshal/ListType.java:286
@Override
public void forEach(ByteBuffer input, Consumer<ByteBuffer> action)
{
serializer.forEach(input, action);
}
@Override
public ByteBuffer getMaskedValue()
{
return decompose(Collections.emptyList());
}
@Override
public List<ByteBuffer> filterSortAndValidateElements(List<ByteBuffer> buffers)
{
for (ByteBuffer buffer: buffers)
{
if (buffer == null)
throw new MarshalException("null is not supported inside collections");
elements.validate(buffer);
}
return buffers;
}
@Override
public List<byte[]> filterSortAndValidateElementsFromArrays(List<byte[]> buffers)
{
for (byte[] buffer: buffers)
{
if (buffer == null)
throw new MarshalException("null is not supported inside collections");
elements.validate(buffer, ByteArrayAccessor.instance);
}
return buffers;
}
@OverrideView on GitHub (pinned to 88fd0f6a0e)
Solutions
- Filter out null buffers before calling filterSortAndValidateElements.
- Use empty/serialized defaults instead of null where a placeholder is needed.
- Validate the collection contents at the application boundary before writing.
Example fix
// before List<ByteBuffer> bufs = rows.stream().map(r -> r.buf).collect(toList()); // may contain null type.filterSortAndValidateElements(bufs); // after List<ByteBuffer> bufs = rows.stream().map(r -> r.buf).filter(Objects::nonNull).collect(toList()); type.filterSortAndValidateElements(bufs);
Defensive patterns
Strategy: validation
Validate before calling
for (ByteBuffer b : buffers) { if (b == null) throw new IllegalArgumentException("null element buffer in list"); } Type guard
List<ByteBuffer> nonNull(List<ByteBuffer> in) { return in.stream().filter(Objects::nonNull).collect(Collectors.toList()); } Try / catch
try { return listType.filterSortAndValidateElements(buffers); } catch (MarshalException e) { throw new DataConstraintException("List contains null elements", e); } Prevention
- Never map nullable language collections directly onto Cassandra list values.
- Serialize defaults (empty values) instead of leaving null slots.
- Run filterSortAndValidateElements as a pre-write sanity check in tooling.
When it happens
Trigger: Programmatic use of ListType (e.g. building collection values via the driver or internal APIs) passing a list of ByteBuffers that contains null; deserialization paths constructing lists with null entries.
Common situations: Custom serialization code that leaves slots null; interop layers mapping nullable language collections directly onto Cassandra lists; drivers or tools that don't pre-filter nulls.
Related errors
- Invalid null element in list
- null is not supported inside vectors
- Element at index %d is null (expected type %s); given %s
- Output file name must not be null or empty.
- Command can not be null or blank string.
AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10).
Data as JSON: /api/errors/22a7ce85ee384077.
Report an issue: GitHub.