apache/cassandra · error · IllegalArgumentException

Maximum number of workers must not be negative

Error message

Maximum number of workers must not be negative

What it means

setMaximumPoolSize validates that the requested maximum worker count is non-negative; a negative value would corrupt the shared permit accounting of SharedExecutorPool, so an IllegalArgumentException is thrown before any state changes. It is a simple argument-validation failure.

Source

Thrown at src/java/org/apache/cassandra/concurrent/SEPExecutor.java:375

    public void setCorePoolSize(int newCorePoolSize)
    {
        throw new IllegalArgumentException("Cannot resize core pool size of SEPExecutor");
    }

    @Override
    public int getMaximumPoolSize()
    {
        return maximumPoolSize.get();
    }

    @Override
    public synchronized void setMaximumPoolSize(int newMaximumPoolSize)
    {
        final int oldMaximumPoolSize = maximumPoolSize.get();

        if (newMaximumPoolSize < 0)
        {
            throw new IllegalArgumentException("Maximum number of workers must not be negative");
        }

        int deltaWorkPermits = newMaximumPoolSize - oldMaximumPoolSize;
        if (!maximumPoolSize.compareAndSet(oldMaximumPoolSize, newMaximumPoolSize))
        {
            throw new IllegalStateException("Maximum pool size has been changed while resizing");
        }

        if (deltaWorkPermits == 0)
            return;

        permits.updateAndGet(cur -> updateWorkPermits(cur, workPermits(cur) + deltaWorkPermits));
        logger.info("Resized {} maximum pool size from {} to {}", name, oldMaximumPoolSize, newMaximumPoolSize);

        // If we we have more work permits than before we should spin up a worker now rather than waiting
        // until either a new task is enqueued (if all workers are descheduled) or a spinning worker calls
        // maybeSchedule().
        pool.maybeStartSpinningWorker();

View on GitHub (pinned to 88fd0f6a0e)

Solutions

  1. Clamp/validate the new size before calling: Math.max(0, newSize)
  2. Fix the configuration value or formula that produced the negative number
  3. Check for integer overflow in size calculations; use Math.subtractExact or long arithmetic then clamp
  4. Ensure config parsing rejects negative pool sizes at load time

Example fix

// before
executor.setMaximumPoolSize(currentSize - reduction); // may go negative
// after
int newSize = Math.max(0, currentSize - reduction);
executor.setMaximumPoolSize(newSize);
Defensive patterns

Strategy: validation

Validate before calling

if (newSize < 0)
    throw new IllegalArgumentException("newMaximumPoolSize must be >= 0, got " + newSize);

Type guard

static boolean isValidPoolSize(int size)
{
    return size >= 0;
}

Prevention

When it happens

Trigger: Calling setMaximumPoolSize with a negative int, e.g. from a computed value like maxSize - delta where delta exceeds maxSize, config parsing that yields a negative number, or integer overflow producing a negative result.

Common situations: Config mistakes where a resize value is subtracted without clamping; user-provided pool settings parsed into int with a sign error; arithmetic overflow when scaling pool sizes programmatically.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


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