{"record":{"id":"0406814290b85a44","repo":"quarkusio/quarkus","slug":"seconds-cannot-be-negative-040681","errorCode":null,"errorMessage":"seconds cannot be negative","messagePattern":"seconds cannot be negative","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"extensions/narayana-jta/runtime/src/main/java/io/quarkus/narayana/jta/RunOptionsBase.java","lineNumber":18,"sourceCode":"package io.quarkus.narayana.jta;\n\nimport java.util.function.Function;\n\n/**\n * An abstract base for both {@link RunOptions} and {@link TransactionRunnerImpl}.\n * <p>\n * Necessary because having {@link RunOptions} extend {@link TransactionRunnerImpl}.,\n * or the other way around, results in signature conflicts in {@code exceptionHandler(Function)}.\n */\nclass RunOptionsBase {\n    TransactionSemantics semantics = TransactionSemantics.REQUIRE_NEW;\n    int timeout = 0;\n    Function<Throwable, TransactionExceptionResult> exceptionHandler;\n\n    RunOptionsBase setTimeout(int seconds) {\n        if (seconds < 0) {\n            throw new IllegalArgumentException(\"seconds cannot be negative\");\n        }\n        this.timeout = seconds;\n        return this;\n    }\n\n    RunOptionsBase setSemantics(TransactionSemantics semantics) {\n        this.semantics = semantics;\n        return this;\n    }\n\n    RunOptionsBase setExceptionHandler(Function<Throwable, TransactionExceptionResult> handler) {\n        this.exceptionHandler = handler;\n        return this;\n    }\n}\n","sourceCodeStart":1,"sourceCodeEnd":34,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/extensions/narayana-jta/runtime/src/main/java/io/quarkus/narayana/jta/RunOptionsBase.java#L1-L34","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","solutions":["Pass a non-negative value; use 0 to mean 'use default'","Clamp the computed value: Math.max(0, computedSeconds)","Validate any config/environment source feeding the timeout before calling timeout()"],"exampleFix":"// before\noptions.timeout(deadline - now);\n// after\noptions.timeout(Math.max(0, (int) Duration.between(Instant.now(), deadline).getSeconds()));","handlingStrategy":"validation","validationCode":"if (seconds < 0) throw new IllegalArgumentException(\"timeout must be >= 0\");","typeGuard":null,"tryCatchPattern":"try { opts = new RunOptions().timeout(seconds); } catch (IllegalArgumentException e) { opts = new RunOptions().timeout(0); }","preventionTips":["Clamp computed timeouts with Math.max(0, value)","Validate config-derived timeout values at startup","Use 0 for 'default timeout', not negative values"],"tags":["narayana-jta","transactions","illegal-argument","validation","timeout"],"backgroundTag":"invalid-argument-value","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}