apache/cassandra · error · MarshalException
null is not supported inside collections
Error message
null is not supported inside collections
What it means
MapType.filterSortAndValidateElements() validates serialized map element pairs: it walks the serialized buffer in key/value pairs and throws MarshalException if any key or value byte slice is null. Null elements are not representable or permitted inside Cassandra collections.
Source
Thrown at src/java/org/apache/cassandra/db/marshal/MapType.java:422
@Override
public List<byte[]> filterSortAndValidateElementsFromArrays(List<byte[]> buffers)
{
return filterSortAndValidateElements(buffers, ByteArrayAccessor.instance, getKeysType().comparatorSet.array);
}
private <T> List<T> filterSortAndValidateElements(List<T> buffers, ValueAccessor<T> valueAccessor, Comparator<T> comparator)
{
// We depend on Maps to be properly sorted by their keys, so use a sorted map implementation here.
SortedMap<T, T> map = new TreeMap<>(comparator);
Iterator<T> iter = buffers.iterator();
while (iter.hasNext())
{
T keyBytes = iter.next();
T valueBytes = iter.next();
if (keyBytes == null || valueBytes == null)
throw new MarshalException("null is not supported inside collections");
getKeysType().validate(keyBytes, valueAccessor);
getValuesType().validate(valueBytes, valueAccessor);
map.put(keyBytes, valueBytes);
}
List<T> sortedBuffers = new ArrayList<>(map.size() << 1);
for (Map.Entry<T, T> entry : map.entrySet())
{
sortedBuffers.add(entry.getKey());
sortedBuffers.add(entry.getValue());
}
return sortedBuffers;
}
protected int compareNextCell(Iterator<Cell<?>> cellIterator, Iterator<ByteBuffer> elementIter)
{View on GitHub (pinned to 88fd0f6a0e)
Solutions
- Ensure map values bound to collection columns contain no null keys or null values; filter them out client-side before binding.
- Use a separate DELETE statement to remove entries rather than binding null values.
- Catch MarshalException around statement binding/execution and sanitize the collection input.
Example fix
// before map.put(1, null); // bound to map<int,text> column // after map.remove(1); // or provide a non-null value
Defensive patterns
Strategy: validation
Validate before calling
for (Map.Entry<K,V> e : boundMap.entrySet()) {
if (e.getKey() == null || e.getValue() == null)
throw new IllegalArgumentException("collection bind values must not contain null keys/values");
} Try / catch
try {
statement.bind(map);
} catch (MarshalException e) {
if (e.getMessage().contains("null is not supported inside collections")) {
// sanitize map and rebind
}
} Prevention
- Filter null keys/values from Java maps before binding to collection columns
- Model removal with DELETE statements, not null values
- Add unit tests for bind payloads containing nulls
When it happens
Trigger: Calling filterSortAndValidateElements (or filterSortAndValidateElementsFromArrays) with serialized map data containing null key or value buffers — typically from bind values where a map entry's key or value is null.
Common situations: Prepared-statement binds with Java maps containing null keys/values; protocol-level collection serialization bugs; client drivers encoding nulls into collection payloads.
Related errors
- Map keys cannot be null
- Map values cannot be null
- Invalid null key in map
- Invalid null value in map
- Null value read when not allowed
AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10).
Data as JSON: /api/errors/0c044e2e7f4aac89.
Report an issue: GitHub.