quarkusio/quarkus · error · IllegalArgumentException

seconds cannot be negative

Error message

seconds cannot be negative

What it means

RunOptionsBase.setTimeout(int) rejects negative timeout values with this IllegalArgumentException. Timeout is the transaction timeout in seconds; 0 means use the global default. Negative values are meaningless, so the builder fails fast.

Source

Thrown at extensions/narayana-jta/runtime/src/main/java/io/quarkus/narayana/jta/RunOptionsBase.java:18

package io.quarkus.narayana.jta;

import java.util.function.Function;

/**
 * An abstract base for both {@link RunOptions} and {@link TransactionRunnerImpl}.
 * <p>
 * Necessary because having {@link RunOptions} extend {@link TransactionRunnerImpl}.,
 * or the other way around, results in signature conflicts in {@code exceptionHandler(Function)}.
 */
class RunOptionsBase {
    TransactionSemantics semantics = TransactionSemantics.REQUIRE_NEW;
    int timeout = 0;
    Function<Throwable, TransactionExceptionResult> exceptionHandler;

    RunOptionsBase setTimeout(int seconds) {
        if (seconds < 0) {
            throw new IllegalArgumentException("seconds cannot be negative");
        }
        this.timeout = seconds;
        return this;
    }

    RunOptionsBase setSemantics(TransactionSemantics semantics) {
        this.semantics = semantics;
        return this;
    }

    RunOptionsBase setExceptionHandler(Function<Throwable, TransactionExceptionResult> handler) {
        this.exceptionHandler = handler;
        return this;
    }
}

View on GitHub (pinned to e1c734241f)

Solutions

  1. Pass a non-negative value; use 0 to mean 'use default'
  2. Clamp the computed value: Math.max(0, computedSeconds)
  3. Validate any config/environment source feeding the timeout before calling timeout()

Example fix

// before
options.timeout(deadline - now);
// after
options.timeout(Math.max(0, (int) Duration.between(Instant.now(), deadline).getSeconds()));
Defensive patterns

Strategy: validation

Validate before calling

if (seconds < 0) throw new IllegalArgumentException("timeout must be >= 0");

Try / catch

try { opts = new RunOptions().timeout(seconds); } catch (IllegalArgumentException e) { opts = new RunOptions().timeout(0); }

Prevention

When it happens

Trigger: Calling setTimeout(seconds) with seconds < 0, e.g. new RunOptions().timeout(-1), or passing a computed/deserialized value that became negative (arithmetic, config parsing, int overflow wrapping).

Common situations: Computing a timeout from config or environment variables that was parsed as negative; subtracting deadlines (deadline - now) that already passed; typos like timeout(-5) intending a default.

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 quarkusio/quarkus@e1c734241f (2026-09-05). Data as JSON: /api/errors/0406814290b85a44. Report an issue: GitHub.