{"record":{"id":"e2640cfc49230197","repo":"apache/pulsar","slug":"recoverthreshold-must-be-larger-than-0","errorCode":null,"errorMessage":"recoverThreshold must be larger than 0","messagePattern":"recoverThreshold must be larger than 0","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"pulsar-client/src/main/java/org/apache/pulsar/client/impl/SameAuthParamsLookupAutoClusterFailover.java","lineNumber":327,"sourceCode":"        return new Builder();\n    }\n\n    public static class Builder {\n\n        private SameAuthParamsLookupAutoClusterFailover\n                sameAuthParamsLookupAutoClusterFailover = new SameAuthParamsLookupAutoClusterFailover();\n\n        public Builder failoverThreshold(int failoverThreshold) {\n            if (failoverThreshold < 1) {\n                throw new IllegalArgumentException(\"failoverThreshold must be larger than 0\");\n            }\n            sameAuthParamsLookupAutoClusterFailover.failoverThreshold = failoverThreshold;\n            return this;\n        }\n\n        public Builder recoverThreshold(int recoverThreshold) {\n            if (recoverThreshold < 1) {\n                throw new IllegalArgumentException(\"recoverThreshold must be larger than 0\");\n            }\n            sameAuthParamsLookupAutoClusterFailover.recoverThreshold = recoverThreshold;\n            return this;\n        }\n\n        public Builder checkHealthyIntervalMs(int checkHealthyIntervalMs) {\n            if (checkHealthyIntervalMs < 1) {\n                throw new IllegalArgumentException(\"checkHealthyIntervalMs must be larger than 0\");\n            }\n            sameAuthParamsLookupAutoClusterFailover.checkHealthyIntervalMs = checkHealthyIntervalMs;\n            return this;\n        }\n\n        public Builder testTopic(String testTopic) {\n            if (StringUtils.isBlank(testTopic) && TopicName.get(testTopic) != null) {\n                throw new IllegalArgumentException(\"testTopic can not be blank\");\n            }\n            sameAuthParamsLookupAutoClusterFailover.testTopic = testTopic;","sourceCodeStart":309,"sourceCodeEnd":345,"githubUrl":"https://github.com/apache/pulsar/blob/820761864ed8e2a7d2e52dd9763ad2ae117c1395/pulsar-client/src/main/java/org/apache/pulsar/client/impl/SameAuthParamsLookupAutoClusterFailover.java#L309-L345","documentation":"The Builder.recoverThreshold(int) setter validates that the recover threshold (consecutive successful probes before switching back to the primary cluster) is at least 1. A value below 1 would make fail-back logic nonsensical, so IllegalArgumentException is thrown.","triggerScenarios":"Calling recoverThreshold(0) or a negative value on the SameAuthParamsLookupAutoClusterFailover Builder, often from an unset config field defaulting to 0.","commonSituations":"Missing config entry for the recover threshold; copy-pasted builder code where the wrong variable (e.g. an uninitialized counter) is passed.","solutions":["Pass a positive integer (>= 1) to recoverThreshold.","Apply a documented default when the configuration value is absent or zero before building.","Validate all failover-related integers together in one config-validation pass."],"exampleFix":"// before\nbuilder.recoverThreshold(props.get(\"recoverThreshold\", 0));\n\n// after\nbuilder.recoverThreshold(Math.max(1, props.get(\"recoverThreshold\", 3)));","handlingStrategy":"validation","validationCode":"int recoverThreshold = cfg.getRecoverThreshold();\nif (recoverThreshold < 1) {\n    recoverThreshold = 3;\n}","typeGuard":null,"tryCatchPattern":"try {\n    builder.recoverThreshold(t);\n} catch (IllegalArgumentException e) {\n    log.warn(\"Invalid recoverThreshold, using default 3\", e);\n    builder.recoverThreshold(3);\n}","preventionTips":["Default unset threshold config to documented positive values.","Group-validate failoverThreshold/recoverThreshold/checkHealthyIntervalMs together.","Reject zero/negative values in your own config validator with a clear message."],"tags":["pulsar-client","configuration","validation","illegal-argument"],"backgroundTag":"invalid-config-value","analyzedSha":"820761864ed8e2a7d2e52dd9763ad2ae117c1395","analyzedAt":"2026-09-06T00:14:20.138Z","contentChangedAt":"2026-09-06T00:14:20.138Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}