apache/cassandra · error · InvalidRequestException
Invalid null value for element selection on <columnName>
Error message
Invalid null value for element selection on <columnName>
What it means
For collection element selection (e.g. col[key] on a map/list/set column), the bound key value must be non-null; bindAndGet returning null (null literal or null bound variable) is rejected. (An UNSET marker is separately rejected with a sibling message.)
Source
Thrown at src/java/org/apache/cassandra/cql3/selection/ElementsSelector.java:154
* is selected.
* @param type the type of the collection.
* @param key the element within the value represented by {@code factory} that is selected.
* @return the created factory.
*/
public static Factory newElementFactory(String name, Selector.Factory factory, CollectionType<?> type, final Term key)
{
return new AbstractFactory(name, factory, type)
{
protected AbstractType<?> getReturnType()
{
return valueType(type);
}
public Selector newInstance(QueryOptions options) throws InvalidRequestException
{
ByteBuffer keyValue = key.bindAndGet(options);
if (keyValue == null)
throw new InvalidRequestException("Invalid null value for element selection on " + factory.getColumnName());
if (keyValue == ByteBufferUtil.UNSET_BYTE_BUFFER)
throw new InvalidRequestException("Invalid unset value for element selection on " + factory.getColumnName());
return new ElementSelector(factory.newInstance(options), keyValue);
}
public boolean areAllFetchedColumnsKnown()
{
// If we known all the fetched columns, it means that we don't have to wait execution to create
// the ColumnFilter (through addFetchedColumns below).
// That's the case if either there is no particular subselection
// to add, or if there is one but the selected key is terminal. In other words,
// we known all the fetched columns if all the feched columns of the factory are known and either:
// 1) the type is frozen (in which case there isn't subselection to do).
// 2) the factory (the left-hand-side) isn't a simple column selection (here again, no
// subselection we can do).
// 3) the element selected is terminal.
return factory.areAllFetchedColumnsKnown()
&& (!type.isMultiCell() || !factory.isSimpleSelectorFactory() || key.isTerminal());View on GitHub (pinned to 88fd0f6a0e)
Solutions
- Bind a concrete non-null key value before executing the statement.
- Remove the element-selection term if the key is unknown and filter/read the whole collection instead.
- Validate parameters at the application layer so null keys never reach the query.
Example fix
// before
BoundStatement bs = ps.bind(); // mapKey left unbound/null
session.execute(bs.bind("SELECT m[?] FROM t WHERE pk = ?", mapKey, pk));
// after
if (mapKey == null) throw new IllegalArgumentException("map key required");
session.execute(ps.bind(mapKey, pk)); Defensive patterns
Strategy: validation
Validate before calling
if (mapKey == null)
throw new IllegalArgumentException("element selection key must not be null");
if (mapKey == ByteBufferUtil.UNSET_BYTE_BUFFER)
throw new IllegalArgumentException("element selection key must be set"); Try / catch
try { session.execute(stmt); }
catch (InvalidRequestException e) {
if (e.getMessage().contains("Invalid null value for element selection")) { /* fix bound key, retry */ }
else throw e;
} Prevention
- Always bind explicit non-null values for element-selection keys.
- Reject null/unset map keys in the data-access layer before building statements.
- Distinguish 'not provided' (skip the term) from 'null key' in query builders.
When it happens
Trigger: A SELECT ... FROM t WHERE / selection using m[?] or m[null] where the marker is bound to null in QueryOptions, i.e. a null or missing bound value for the element-selection key.
Common situations: Driver statements with unset/null parameters for the map key in element selection; also literal 'm[null]' expressions written by mistake.
Related errors
- Invalid operation (%s) for set column %s
- category %s not found in %s
- GRANT operation is not supported by AllowAllAuthorizer
- REVOKE operation is not supported by AllowAllAuthorizer
- LIST PERMISSIONS operation is not supported by AllowAllAutho
AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10).
Data as JSON: /api/errors/544bfa851aac1f2f.
Report an issue: GitHub.