{"record":{"id":"71fe4338130e569c","repo":"aeron-io/aeron","slug":"newleadertimeoutns-must-be-positive-or-1-but-was","errorCode":null,"errorMessage":"newLeaderTimeoutNs must be positive or -1, but was <newLeaderTimeoutNs>","messagePattern":"newLeaderTimeoutNs must be positive or -1, but was <newLeaderTimeoutNs>","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"aeron-cluster/src/main/java/io/aeron/cluster/client/AeronCluster.java","lineNumber":1600,"sourceCode":"        @Config\n        public long messageTimeoutNs()\n        {\n            return CommonContext.checkDebugTimeout(messageTimeoutNs, TimeUnit.NANOSECONDS);\n        }\n\n        /**\n         * The timeout to wait for a new leader after noticing a disconnection from the previous one. Upon timeout the\n         * cluster will be considered lost and the client will close. If set to {@link Aeron#NULL_VALUE}, a reasonable\n         * default will be used.\n         *\n         * @param newLeaderTimeoutNs the new leader timeout in nanoseconds or {@link Aeron#NULL_VALUE}.\n         * @return this for a fluent API.\n         */\n        public Context newLeaderTimeoutNs(final long newLeaderTimeoutNs)\n        {\n            if (!(0 < newLeaderTimeoutNs || NULL_VALUE == newLeaderTimeoutNs))\n            {\n                throw new IllegalArgumentException(\n                    \"newLeaderTimeoutNs must be positive or -1, but was \" + newLeaderTimeoutNs);\n            }\n            this.newLeaderTimeoutNs = newLeaderTimeoutNs;\n            return this;\n        }\n\n        /**\n         * The timeout to wait for a new leader after noticing a disconnection from the previous one. Upon timeout the\n         * cluster will be considered lost and the client will close.\n         *\n         * @return the new leader timeout in nanoseconds.\n         */\n        public long newLeaderTimeoutNs()\n        {\n            return CommonContext.checkDebugTimeout(newLeaderTimeoutNs, TimeUnit.NANOSECONDS);\n        }\n\n        /**","sourceCodeStart":1582,"sourceCodeEnd":1618,"githubUrl":"https://github.com/aeron-io/aeron/blob/6d60124e15e35c11b49ba2e3c2c2858a09a18803/aeron-cluster/src/main/java/io/aeron/cluster/client/AeronCluster.java#L1582-L1618","documentation":"newLeaderTimeoutNs controls how long the client waits for a new leader before failing. Context.newLeaderTimeoutNs() validates the value with IllegalArgumentException: it must be strictly positive or the NULL_VALUE (-1) sentinel meaning use the default; zero and other negatives are rejected.","triggerScenarios":"Calling ctx.newLeaderTimeoutNs(0) or any negative value other than -1 (NULL_VALUE).","commonSituations":"Passing a timeout in different units that rounds to 0; using 0 to mean 'no wait' (not supported); computing the value from config where 0/null handling goes wrong.","solutions":["Pass a positive value in nanoseconds, e.g. TimeUnit.SECONDS.toNanos(30)","Pass AeronCluster.NULL_VALUE (-1) to accept the library default","Fix config parsing so 0/negative inputs map to the default rather than being forwarded"],"exampleFix":"// before\nlong timeout = config.getTimeoutMs(); // may be 0\nctx.newLeaderTimeoutNs(timeout);\n// after\nlong timeoutMs = config.getTimeoutMs();\nlong timeoutNs = timeoutMs > 0 ? TimeUnit.MILLISECONDS.toNanos(timeoutMs) : AeronCluster.NULL_VALUE;\nctx.newLeaderTimeoutNs(timeoutNs);","handlingStrategy":"validation","validationCode":"long ns = configuredTimeout;\nif (!(ns > 0 || ns == AeronCluster.NULL_VALUE)) {\n    throw new IllegalArgumentException(\"newLeaderTimeoutNs must be positive or NULL_VALUE(-1), got \" + ns);\n}\nctx.newLeaderTimeoutNs(ns);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Map unit conversions so a 0 or unset timeout becomes NULL_VALUE (default) rather than 0","Validate timeout config (unit, sign) at load time"],"tags":["configuration","timeout","validation"],"backgroundTag":"invalid-argument-value","analyzedSha":"6d60124e15e35c11b49ba2e3c2c2858a09a18803","analyzedAt":"2026-09-12T11:17:07.683Z","contentChangedAt":"2026-09-12T11:17:07.683Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}