eclipse-vertx/vert.x · error · IllegalArgumentException

Invalid amount: ${amount}

Error message

Invalid amount: ${amount}

What it means

InboundMessageQueue.fetch(long) implements Reactive Streams-style demand; a negative amount would corrupt the demand counter, so it throws IllegalArgumentException. Zero is allowed (no-op), but negative values are rejected.

Source

Thrown at vertx-core/src/main/java/io/vertx/core/internal/concurrent/InboundMessageQueue.java:200

      draining = false;
    }
  }

  /**
   * Clear the demand.
   */
  public final void pause() {
    DEMAND_UPDATER.set(this, 0L);
  }

  /**
   * Add {@code amount} to the current demand.
   *
   * @param amount the number of message to consume
   */
  public final void fetch(long amount) {
    if (amount < 0L) {
      throw new IllegalArgumentException("Invalid amount: " + amount);
    }
    if (amount > 0L) {
      while (true) {
        long prev = DEMAND_UPDATER.get(this);
        long next = prev + amount;
        if (next < 0L) {
          next = Long.MAX_VALUE;
        }
        if (prev == next || DEMAND_UPDATER.compareAndSet(this, prev, next)) {
          break;
        }
      }
      consumer.execute(this);
    }
  }

  /**
   * Close the queue.

View on GitHub (pinned to fb308bd8c3)

Solutions

  1. Clamp or validate the amount: if (n > 0) queue.fetch(n)
  2. Ignore non-positive requests as the Reactive Streams spec requires (only forward n > 0)
  3. Fix the upstream computation that produced the negative demand

Example fix

// before
queue.fetch(remaining); // remaining can be negative
// after
if (remaining > 0) {
  queue.fetch(remaining);
}
Defensive patterns

Strategy: validation

Validate before calling

if (n > 0) queue.fetch(n); // per Reactive Streams, ignore n <= 0

Try / catch

try { queue.fetch(amount); } catch (IllegalArgumentException e) { log.warn("ignoring invalid demand {}", amount); }

Prevention

When it happens

Trigger: Calling queue.fetch(-1) or passing a computed negative request count into fetch(); relaying an upstream request(n) with n < 0 into the queue's fetch.

Common situations: Buggy backpressure math (received - requested going negative); forwarding subscriber.request() values without validating against the Reactive Streams rule that n must be > 0.

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 eclipse-vertx/vert.x@fb308bd8c3 (2026-09-06). Data as JSON: /api/errors/b7ce331fc29c8210. Report an issue: GitHub.