{"record":{"id":"b7ce331fc29c8210","repo":"eclipse-vertx/vert.x","slug":"invalid-amount-amount","errorCode":null,"errorMessage":"Invalid amount: ${amount}","messagePattern":"Invalid amount: (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"vertx-core/src/main/java/io/vertx/core/internal/concurrent/InboundMessageQueue.java","lineNumber":200,"sourceCode":"      draining = false;\n    }\n  }\n\n  /**\n   * Clear the demand.\n   */\n  public final void pause() {\n    DEMAND_UPDATER.set(this, 0L);\n  }\n\n  /**\n   * Add {@code amount} to the current demand.\n   *\n   * @param amount the number of message to consume\n   */\n  public final void fetch(long amount) {\n    if (amount < 0L) {\n      throw new IllegalArgumentException(\"Invalid amount: \" + amount);\n    }\n    if (amount > 0L) {\n      while (true) {\n        long prev = DEMAND_UPDATER.get(this);\n        long next = prev + amount;\n        if (next < 0L) {\n          next = Long.MAX_VALUE;\n        }\n        if (prev == next || DEMAND_UPDATER.compareAndSet(this, prev, next)) {\n          break;\n        }\n      }\n      consumer.execute(this);\n    }\n  }\n\n  /**\n   * Close the queue.","sourceCodeStart":182,"sourceCodeEnd":218,"githubUrl":"https://github.com/eclipse-vertx/vert.x/blob/fb308bd8c3f12c79f4ae89bef67fadf6c80d036e/vertx-core/src/main/java/io/vertx/core/internal/concurrent/InboundMessageQueue.java#L182-L218","documentation":"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.","triggerScenarios":"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.","commonSituations":"Buggy backpressure math (received - requested going negative); forwarding subscriber.request() values without validating against the Reactive Streams rule that n must be > 0.","solutions":["Clamp or validate the amount: if (n > 0) queue.fetch(n)","Ignore non-positive requests as the Reactive Streams spec requires (only forward n > 0)","Fix the upstream computation that produced the negative demand"],"exampleFix":"// before\nqueue.fetch(remaining); // remaining can be negative\n// after\nif (remaining > 0) {\n  queue.fetch(remaining);\n}","handlingStrategy":"validation","validationCode":"if (n > 0) queue.fetch(n); // per Reactive Streams, ignore n <= 0","typeGuard":null,"tryCatchPattern":"try { queue.fetch(amount); } catch (IllegalArgumentException e) { log.warn(\"ignoring invalid demand {}\", amount); }","preventionTips":["Follow the Reactive Streams rule: only request/fetch positive amounts","Guard backpressure arithmetic against underflow (requested - granted can go negative)","Validate upstream subscriber.request(n) values before relaying them"],"tags":["backpressure","reactive-streams","illegal-argument"],"backgroundTag":"invalid-argument-value","analyzedSha":"fb308bd8c3f12c79f4ae89bef67fadf6c80d036e","analyzedAt":"2026-09-06T11:37:12.241Z","contentChangedAt":"2026-09-06T11:37:12.241Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}