apache/cassandra · error · InvalidRequestException

Attempted to delete an element from a list which is null

Error message

Attempted to delete an element from a list which is null

What it means

Thrown when deleting a list element by index on a row whose list column is null or empty (no existing collection data). Since there is no element to remove, Cassandra rejects the delete rather than silently no-op-ing.

Solutions

  1. Check that the row exists and the list is non-empty before issuing an index-based delete.
  2. Set the list first (e.g. `SET l = ?`) or use `l = l - ?` element-based removal which tolerates missing elements.
  3. Handle InvalidRequestException for this case and treat it as a no-op in application logic.

Example fix

// before
session.execute("DELETE l[?] FROM t WHERE k=?", idx, key);
// after
Row row = session.execute("SELECT l FROM t WHERE k=?", key).one();
if (row != null && !row.isNull("l"))
    session.execute("DELETE l[?] FROM t WHERE k=?", idx, key);
Defensive patterns

Strategy: validation

Validate before calling

Row r = session.execute("SELECT l FROM t WHERE k=?", key).one();
if (r == null || r.isNull("l")) return; // nothing to delete

Type guard

boolean listExists(Row r, String col) { return r != null && !r.isNull(col); }

Try / catch

try { session.execute("DELETE l[?] FROM t WHERE k=?", idx, key); } catch (InvalidRequestException e) { if (e.getMessage().contains("list which is null")) { /* treat as no-op */ } else throw e; }

Prevention

When it happens

Trigger: `DELETE l[?] FROM t WHERE ...` where the target row has no list value (list is null) or exists with size 0, and the index binds to a valid non-null value.

Common situations: Deleting by index on a row that was never written with a list; rows where the list was previously set to null; concurrent deletes that emptied the list between read and write.

Understand the failure class

Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.

Related errors


AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10). Data as JSON: /api/errors/e1bafa17c8a66f84. Report an issue: GitHub.

Appendix: source

Thrown at src/java/org/apache/cassandra/cql3/terms/Lists.java:563

        public void execute(DecoratedKey partitionKey, RowUpdateBuilder builder) throws InvalidRequestException
        {
            assert column.type.isMultiCell() : "Attempted to delete an item by index from a frozen list";

            Guardrails.readBeforeWriteListOperationsEnabled
            .ensureEnabled("Removal of list items by index requiring read before write", builder.clientState);

            Term.Terminal index = t.bind(builder);
            if (index == null)
                throw new InvalidRequestException("Invalid null value for list index");
            if (index == Constants.UNSET_VALUE)
                return;

            Row existingRow = builder.getPrefetchedRow(partitionKey, builder.currentClustering());
            int existingSize = existingSize(existingRow, column);
            int idx = ByteBufferUtil.toInt(index.get());
            if (existingSize == 0)
                throw new InvalidRequestException("Attempted to delete an element from a list which is null");
            if (idx < 0 || idx >= existingSize)
                throw new InvalidRequestException(String.format("List index %d out of bound, list has size %d", idx, existingSize));

            builder.addTombstone(column, existingRow.getComplexColumnData(column).getCellByIndex(idx).path());
        }
    }
}

View on GitHub (pinned to 88fd0f6a0e)