quarkusio/quarkus · error · IllegalArgumentException

seconds cannot be negative

Error message

seconds cannot be negative

What it means

BeginOptions.timeout(int) validates that the transaction timeout is not negative and throws IllegalArgumentException for seconds < 0. Negative timeouts are meaningless for Narayana transaction timeouts, so the builder rejects them eagerly.

Source

Thrown at extensions/narayana-jta/runtime/src/main/java/io/quarkus/narayana/jta/BeginOptions.java:33

     * <p>
     *
     * @return These options
     */
    public BeginOptions commitOnRequestScopeEnd() {
        commitOnRequestScopeEnd = true;
        return this;
    }

    /**
     * Sets the transaction timeout for transactions created by this builder. A value of zero refers to the system default.
     *
     * @param seconds The timeout in seconds
     * @return This builder
     * @throws IllegalArgumentException If seconds is negative
     */
    public BeginOptions timeout(int seconds) {
        if (seconds < 0) {
            throw new IllegalArgumentException("seconds cannot be negative");
        }
        this.timeout = seconds;
        return this;
    }
}

View on GitHub (pinned to e1c734241f)

Solutions

  1. Pass only non-negative values; clamp with Math.max(0, seconds)
  2. Fix the computation producing the negative timeout (check elapsed-time calculations)
  3. Omit the timeout call to use the default transaction timeout

Example fix

// before
BeginOptions opts = new BeginOptions().timeout(remainingSeconds); // may be -3
// after
BeginOptions opts = new BeginOptions().timeout(Math.max(0, remainingSeconds));
Defensive patterns

Strategy: validation

Validate before calling

if (seconds < 0) {
    throw new IllegalArgumentException("timeout must be >= 0, got " + seconds);
}
BeginOptions opts = new BeginOptions().timeout(seconds);

Try / catch

try {
    opts = new BeginOptions().timeout(computedSeconds);
} catch (IllegalArgumentException e) {
    opts = new BeginOptions(); // default timeout
}

Prevention

When it happens

Trigger: Calling QuarkusTransaction.begin(options built with .timeout(-1)) or otherwise passing a negative value to BeginOptions.timeout(int).

Common situations: Computing a timeout from configuration or a deadline calculation that can yield negative values (e.g. remaining = deadline - now when the deadline already passed); off-by-one subtraction bugs.

Related errors


AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05). Data as JSON: /api/errors/5bbd68b2c578b4ab. Report an issue: GitHub.