apache/cassandra · error · MarshalException
null is not supported inside collections
Error message
null is not supported inside collections
What it means
SetType validates every element buffer supplied when constructing a set value. Cassandra sets cannot contain null elements, so if any buffer in the incoming list is null the type throws this MarshalException before sorting/validating elements. It protects the internal sorted-set representation from nulls.
Source
Thrown at src/java/org/apache/cassandra/db/marshal/SetType.java:283
@Override
public List<ByteBuffer> filterSortAndValidateElements(List<ByteBuffer> buffers)
{
return filterSortAndValidateElements(buffers, ByteBufferAccessor.instance, elements.comparatorSet.buffer);
}
@Override
public List<byte[]> filterSortAndValidateElementsFromArrays(List<byte[]> buffers)
{
return filterSortAndValidateElements(buffers, ByteArrayAccessor.instance, elements.comparatorSet.array);
}
private <V> List<V> filterSortAndValidateElements(List<V> buffers, ValueAccessor<V> valueAccessor, Comparator<V> comparator)
{
SortedSet<V> sorted = new TreeSet<>(comparator);
for (V buffer: buffers)
{
if (buffer == null)
throw new MarshalException("null is not supported inside collections");
elements.validate(buffer, valueAccessor);
sorted.add(buffer);
}
return new ArrayList<>(sorted);
}
@Override
protected int compareNextCell(Iterator<Cell<?>> cellIterator, Iterator<ByteBuffer> elementIter)
{
return getElementsType().compare(cellIterator.next().path().get(0), elementIter.next());
}
@Override
public boolean contains(ComplexColumnData columnData, ByteBuffer value)
{
return columnData.getCell(CellPath.create(value)) != null;
}
}View on GitHub (pinned to 88fd0f6a0e)
Solutions
- Filter null elements out of the collection before passing it to SetType (builder.add / decompose).
- Decide the desired semantics: skip nulls, or reject the record upstream with a clearer application-level error.
- Check any JSON/JSONB deserialization path that maps missing fields to null elements and drop them instead.
Example fix
// before List<ByteBuffer> elements = jsonList.stream().map(this::toByteBuffer).collect(toList()); set.decompose(elements); // after List<ByteBuffer> elements = jsonList.stream().filter(Objects::nonNull).map(this::toByteBuffer).collect(toList()); set.decompose(elements);
Defensive patterns
Strategy: validation
Validate before calling
List<ByteBuffer> safe = elements == null ? Collections.emptyList() : elements.stream().filter(Objects::nonNull).collect(Collectors.toList());
Prevention
- Never put null elements into collection builders; filter or map them to defaults first
- Review any JSON/ORM layer that maps missing fields to null collection entries
- Unit-test collection serialization with payloads containing missing values
When it happens
Trigger: Calling SetType.decompose / builder (e.g. SetType.getInstance(...).decompose or ListBox builder) with a list of ByteBuffer elements that contains a null entry; binding a CQL literal or bound value for a set column where one element is null (e.g. SET c = {1, null, 3}).
Common situations: Application code deserializing data from another source that represents missing values as null and passing them straight into a set builder; drivers/JSON-to-CQL converters that do not filter nulls before building collection values.
Related errors
- Unexpected extraneous bytes after + getCollectionName() + va
- Null value read when not allowed
- Not enough bytes to read a list
- Unexpected extraneous bytes after list value
- The data cannot be deserialized as a list
AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10).
Data as JSON: /api/errors/29e1b4258fb47d64.
Report an issue: GitHub.