{"record":{"id":"5bbd68b2c578b4ab","repo":"quarkusio/quarkus","slug":"seconds-cannot-be-negative","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/BeginOptions.java","lineNumber":33,"sourceCode":"     * <p>\n     *\n     * @return These options\n     */\n    public BeginOptions commitOnRequestScopeEnd() {\n        commitOnRequestScopeEnd = true;\n        return this;\n    }\n\n    /**\n     * Sets the transaction timeout for transactions created by this builder. A value of zero refers to the system default.\n     *\n     * @param seconds The timeout in seconds\n     * @return This builder\n     * @throws IllegalArgumentException If seconds is negative\n     */\n    public BeginOptions timeout(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","sourceCodeStart":15,"sourceCodeEnd":39,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/extensions/narayana-jta/runtime/src/main/java/io/quarkus/narayana/jta/BeginOptions.java#L15-L39","documentation":"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.","triggerScenarios":"Calling QuarkusTransaction.begin(options built with .timeout(-1)) or otherwise passing a negative value to BeginOptions.timeout(int).","commonSituations":"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.","solutions":["Pass only non-negative values; clamp with Math.max(0, seconds)","Fix the computation producing the negative timeout (check elapsed-time calculations)","Omit the timeout call to use the default transaction timeout"],"exampleFix":"// before\nBeginOptions opts = new BeginOptions().timeout(remainingSeconds); // may be -3\n// after\nBeginOptions opts = new BeginOptions().timeout(Math.max(0, remainingSeconds));","handlingStrategy":"validation","validationCode":"if (seconds < 0) {\n    throw new IllegalArgumentException(\"timeout must be >= 0, got \" + seconds);\n}\nBeginOptions opts = new BeginOptions().timeout(seconds);","typeGuard":null,"tryCatchPattern":"try {\n    opts = new BeginOptions().timeout(computedSeconds);\n} catch (IllegalArgumentException e) {\n    opts = new BeginOptions(); // default timeout\n}","preventionTips":["Clamp computed timeouts with Math.max(0, ...)","Unit-test timeout derivation from config/deadline math","Prefer omitting the timeout (default) when the computed value may be invalid"],"tags":["narayana","transaction","illegal-argument","validation"],"backgroundTag":"negative-timeout-rejected","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}