apache/cassandra · error · InvalidRequestException

The negation of " + increment + " overflows supported…

Error message

The negation of " + increment + " overflows supported counter precision (signed 8 bytes integer)

What it means

Thrown when negating a counter delta equal to Long.MIN_VALUE (-9223372036854775808). Because -Long.MIN_VALUE overflows in signed 64-bit arithmetic, Cassandra rejects it explicitly instead of silently wrapping the counter.

Solutions

  1. Clamp or validate the delta so it is strictly greater than Long.MIN_VALUE before binding
  2. Split the operation into two smaller counter updates if an equivalent huge decrement is truly needed
  3. Log/reject at the application layer when delta == Long.MIN_VALUE

Example fix

// before
long delta = Long.MIN_VALUE;
session.execute("UPDATE t SET c = c - ?", delta);
// after
if (delta == Long.MIN_VALUE) throw new IllegalArgumentException("delta too small");
session.execute("UPDATE t SET c = c - ?", delta);
Defensive patterns

Strategy: validation

Validate before calling

if (delta == Long.MIN_VALUE) throw new IllegalArgumentException("delta cannot be negated");

Try / catch

try { session.execute(stmt); } catch (InvalidQueryException e) { if (e.getMessage().contains("overflows supported counter precision")) { /* clamp or split the delta */ } else throw e; }

Prevention

When it happens

Trigger: `UPDATE t SET c = -?` where the bound value is exactly Long.MIN_VALUE; literal `SET c = c - (-9223372036854775808)` style extreme deltas.

Common situations: Stress tests or data corruption scenarios using extreme long values; unvalidated user-supplied deltas reaching the extreme negative bound.

Understand the failure class

Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.

Related errors


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

Appendix: source

Thrown at src/java/org/apache/cassandra/cql3/terms/Constants.java:580

        @Override
        public boolean requiresRead()
        {
            return !column.type.isCounter();
        }

        public void execute(DecoratedKey partitionKey, RowUpdateBuilder builder) throws InvalidRequestException
        {
            if (column.type instanceof CounterColumnType)
            {
                ByteBuffer bytes = t.bindAndGet(builder);
                if (bytes == null)
                    throw new InvalidRequestException("Invalid null value for counter increment");
                if (bytes == ByteBufferUtil.UNSET_BYTE_BUFFER)
                    return;

                long increment = ByteBufferUtil.toLong(bytes);
                if (increment == Long.MIN_VALUE)
                    throw new InvalidRequestException("The negation of " + increment + " overflows supported counter precision (signed 8 bytes integer)");

                builder.addCounter(column, -increment);
            }
            else if (column.type instanceof NumberType<?>)
            {
                @SuppressWarnings("unchecked") NumberType<Number> type = (NumberType<Number>) column.type;
                ByteBuffer increment = type.sanitize(t.bindAndGet(builder));
                if (increment == null)
                    return;
                ByteBuffer current = type.sanitize(getCurrentCellBuffer(column, partitionKey, builder));
                if (current == null)
                    return;
                ByteBuffer newValue = type.substract(type.compose(current), type.compose(increment));
                builder.addCell(column, newValue);
            }
        }
    }

View on GitHub (pinned to 88fd0f6a0e)