{"record":{"id":"b347e977438396be","repo":"apache/cassandra","slug":"max-attempt-must-be-positive-but-given-value","errorCode":null,"errorMessage":"max attempt must be positive; but given <value>","messagePattern":"max attempt must be positive; but given <value>","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/config/RetrySpec.java","lineNumber":46,"sourceCode":"import org.apache.cassandra.repair.SharedContext;\nimport org.apache.cassandra.service.RetryStrategy;\nimport org.apache.cassandra.service.TimeoutStrategy.LatencySourceFactory;\nimport org.apache.cassandra.service.WaitStrategy;\n\nimport static org.apache.cassandra.service.RetryStrategy.randomizers;\n\npublic class RetrySpec\n{\n    public static class MaxAttempt\n    {\n        public static final MaxAttempt DISABLED = new MaxAttempt();\n\n        public final int value;\n\n        public MaxAttempt(int value)\n        {\n            if (value < 1)\n                throw new IllegalArgumentException(\"max attempt must be positive; but given \" + value);\n            this.value = value;\n        }\n\n        private MaxAttempt()\n        {\n            value = 0;\n        }\n\n        @Override\n        public boolean equals(Object o)\n        {\n            if (this == o) return true;\n            if (o == null) return false;\n            if (o instanceof Integer) return this.value == ((Integer) o).intValue();\n            if (getClass() != o.getClass()) return false;\n            MaxAttempt that = (MaxAttempt) o;\n            return value == that.value;\n        }","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/config/RetrySpec.java#L28-L64","documentation":"RetrySpec.MaxAttempt is a typed config wrapper enforcing that a retry max-attempt count is at least 1. The constructor throws IllegalArgumentException for any value < 1. It fails fast when YAML or code supplies a zero or negative attempt count.","triggerScenarios":"Configuring a retry spec (e.g. for driver or internal retries) with max_attempt: 0 or a negative integer, in cassandra.yaml or programmatically.","commonSituations":"Setting max_attempt to 0 intending 'unlimited' or 'disabled'; typo or misread units; template configs copied with placeholder values.","solutions":["Set max_attempt to a positive integer (>= 1)","If retries should be disabled, use the mechanism intended for disabling rather than 0 attempts","Validate any programmatically-built retry spec before passing it in"],"exampleFix":"// before\nmax_attempt: 0\n// after\nmax_attempt: 3","handlingStrategy":"validation","validationCode":"int maxAttempt = parseMaxAttempt(yamlValue);\nif (maxAttempt < 1) throw new IllegalArgumentException(\"max attempt must be positive\");","typeGuard":"static boolean isValidMaxAttempt(int v) { return v >= 1; }","tryCatchPattern":"try { new RetrySpec.MaxAttempt(v); }\ncatch (IllegalArgumentException e) { log.warn(\"Falling back to default max attempts\"); }","preventionTips":["Never use 0 to mean 'disabled' — use >= 1 or the explicit disable mechanism","Unit-test typed config wrappers with boundary values (0, -1)","Document valid ranges next to YAML settings"],"tags":["configuration","validation","retry"],"backgroundTag":"invalid-config-value","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}