{"record":{"id":"7af43468e1ea5363","repo":"apache/cassandra","slug":"retries-must-be-non-negative-retries-value-sup","errorCode":null,"errorMessage":"retries must be non-negative (retries=${value} supplied)","messagePattern":"retries must be non-negative \\(retries=(.+?) supplied\\)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/service/RetryStrategy.java","lineNumber":284,"sourceCode":"        String original = spec;\n        int retries = Integer.MAX_VALUE;\n        int end = spec.length();\n        {\n            int next;\n            while ((next = spec.lastIndexOf(',', end - 1)) >= 0)\n            {\n                int mid = spec.indexOf('=', next + 1);\n                if (mid <= next || mid >= end)\n                    throw new IllegalArgumentException(\"Invalid modifier specification: '\" + spec.substring(next, end) + \"'; expecting '=' for value assignment\");\n                String key = spec.substring(next + 1, mid).trim();\n                String value = spec.substring(mid + 1, end).trim();\n                switch (key)\n                {\n                    default: throw new IllegalArgumentException(\"Invalid modifier specification: unrecognised property '\" + key + '\\'');\n                    case \"retries\":\n                        retries = Integer.parseInt(value);\n                        if (retries < 0)\n                            throw new IllegalArgumentException(\"retries must be non-negative (retries=\" + value + \" supplied)\");\n                        break;\n                    case \"attempts\":\n                        retries = Integer.parseInt(value);\n                        if (retries < 0)\n                            throw new IllegalArgumentException(\"Must permit at least one attempt (attempts=\" + value + \" supplied)\");\n                        break;\n                    case \"rnd\":\n                        if (randomizer != null)\n                            throw new IllegalArgumentException(\"Randomizer already specified, cannot re-specify: \" + value);\n                        randomizer = parseWaitRandomizer(value);\n                        break;\n                }\n                end = next;\n            }\n            if (end != spec.length())\n                spec = spec.substring(0, end);\n        }\n","sourceCodeStart":266,"sourceCodeEnd":302,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/service/RetryStrategy.java#L266-L302","documentation":"When parsing a 'retries=<n>' modifier, RetryStrategy.parse() rejects negative values because a negative retry count is meaningless (it would permit fewer than zero retries). An IllegalArgumentException carrying the supplied value is thrown.","triggerScenarios":"RetryStrategy.parse(spec, latencies) where spec ends with ',retries=-1' (or any negative integer). The value must parse as an int >= 0.","commonSituations":"Hand-written config where a negative default like retries=-1 was intended to mean 'unlimited' (use retries=0 or omit the modifier instead); templated config injecting -1 placeholders.","solutions":["Change the retries value to a non-negative integer","To express unlimited retries, omit the modifier (default is Integer.MAX_VALUE retries)","If a negative sentinel was intended as 'disabled', use retries=0 instead"],"exampleFix":"// before\nRetryStrategy.parse(\"100ms,retries=-1\", latencies);\n// after\nRetryStrategy.parse(\"100ms,retries=0\", latencies); // or omit retries for unlimited","handlingStrategy":"validation","validationCode":"static int validateRetries(String value) {\n    int retries = Integer.parseInt(value.trim());\n    if (retries < 0) throw new IllegalArgumentException(\"retries must be >= 0, got \" + value);\n    return retries;\n}","typeGuard":null,"tryCatchPattern":"try {\n    RetryStrategy strategy = RetryStrategy.parse(spec, latencies);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().contains(\"retries must be non-negative\")) {\n        LOG.warn(\"Negative retries in spec '{}', falling back to default\", spec);\n        return RetryStrategy.parse(\"100ms\", latencies);\n    }\n    throw e;\n}","preventionTips":["Never use negative sentinels; use retries=0 to disable or omit for unlimited","Sanitize numeric config values before interpolation into spec strings","Add config schema checks that reject negative integers for retry fields"],"tags":["configuration","parsing","value-range"],"backgroundTag":"value-out-of-range","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}