apache/cassandra · error · MarshalException
Invalid null element in set
Error message
Invalid null element in set
What it means
SetType.fromJSONObject() iterates the decoded JSON array and rejects any null element, because Cassandra sets cannot contain null values. A null in the list raises MarshalException before element terms are built.
Source
Thrown at src/java/org/apache/cassandra/db/marshal/SetType.java:240
return bbs;
}
@Override
public Term fromJSONObject(Object parsed) throws MarshalException
{
if (parsed instanceof String)
parsed = JsonUtils.decodeJson((String) parsed);
if (!(parsed instanceof List))
throw new MarshalException(String.format(
"Expected a list (representing a set), but got a %s: %s", parsed.getClass().getSimpleName(), parsed));
List<?> list = (List<?>) parsed;
List<Term> terms = new ArrayList<>(list.size());
for (Object element : list)
{
if (element == null)
throw new MarshalException("Invalid null element in set");
terms.add(elements.fromJSONObject(element));
}
return new MultiElements.DelayedValue(this, terms);
}
@Override
public String toJSONString(ByteBuffer buffer, ProtocolVersion protocolVersion)
{
return setOrListToJsonString(buffer, elements, protocolVersion);
}
@Override
public void forEach(ByteBuffer input, Consumer<ByteBuffer> action)
{
serializer.forEach(input, action);
}
View on GitHub (pinned to 88fd0f6a0e)
Solutions
- Remove null elements from the JSON array before sending.
- Filter nulls from the decoded List programmatically before calling fromJSONObject.
- Catch MarshalException and surface which set field contained a null element.
Example fix
// before
{"s": [1, null, 3]}
// after
{"s": [1, 3]} Defensive patterns
Strategy: validation
Validate before calling
List<?> list = (List<?>) decoded;
if (list.stream().anyMatch(Objects::isNull))
throw new IllegalArgumentException("set contains a null element"); Try / catch
try {
Term term = setType.fromJSONObject(parsed);
} catch (MarshalException e) {
if (e.getMessage().contains("null element")) {
// strip nulls from list and retry
}
} Prevention
- Strip null items from JSON arrays before ingest
- Model absence by omitting elements, not by sending null
- Sanitize decoded lists: list.removeIf(Objects::isNull)
When it happens
Trigger: Calling fromJSONObject on SetType with a List containing null — e.g. JSON like {"s": [1, null, 3]}.
Common situations: Ingestion pipelines preserving nulls from upstream arrays; clients serializing absent values as null inside JSON arrays; JSON sources containing explicit null array items.
Related errors
- Invalid null key in map
- Invalid null value in map
- Expected a list (representing a set), but got a %s: %s
- Invalid null element in list
- Invalid value for %s: null is not allowed
AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10).
Data as JSON: /api/errors/f59ab9741afef3c5.
Report an issue: GitHub.