{"record":{"id":"3c767680feaa3e87","repo":"apache/cassandra","slug":"invalid-duration-s-it-shouldn-t-be-more-than-d","errorCode":null,"errorMessage":"Invalid duration: %s. It shouldn't be more than %d in %s","messagePattern":"Invalid duration: (.+?)\\. It shouldn't be more than (.+?) in (.+?)","errorType":"validation","errorClass":"java.lang.IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/config/DurationSpec.java","lineNumber":113,"sourceCode":"\n    private static void validateMinUnit(TimeUnit unit, TimeUnit minUnit, String value)\n    {\n        if (unit.compareTo(minUnit) < 0)\n            throw new IllegalArgumentException(String.format(\"Invalid duration: %s Accepted units:%s\", value, acceptedUnits(minUnit)));\n    }\n\n    private static String acceptedUnits(TimeUnit minUnit)\n    {\n        TimeUnit[] units = TimeUnit.values();\n        return Arrays.toString(Arrays.copyOfRange(units, minUnit.ordinal(), units.length));\n    }\n\n    private static void validateQuantity(String value, long quantity, TimeUnit sourceUnit, TimeUnit minUnit, long max)\n    {\n        // no need to validate for negatives as they are not allowed at first place from the regex\n\n        if (minUnit.convert(quantity, sourceUnit) >= max)\n            throw new IllegalArgumentException(\"Invalid duration: \" + value + \". It shouldn't be more than \" +\n                                             (max - 1) + \" in \" + toLowerCaseLocalized(minUnit.name()));\n    }\n\n    private static void validateQuantity(long quantity, TimeUnit sourceUnit, TimeUnit minUnit, long max)\n    {\n        if (quantity < 0)\n            throw new IllegalArgumentException(\"Invalid duration: value must be non-negative\");\n\n        if (minUnit.convert(quantity, sourceUnit) >= max)\n            throw new IllegalArgumentException(String.format(\"Invalid duration: %d %s. It shouldn't be more than %d in %s\",\n                                                           quantity, toLowerCaseLocalized(sourceUnit.name()),\n                                                           max - 1, toLowerCaseLocalized(minUnit.name())));\n    }\n\n    // get vs no-get prefix is not consistent in the code base, but for classes involved with config parsing, it is\n    // imporant to be explicit about get/set as this changes how parsing is done; this class is a data-type, so is\n    // not nested, having get/set can confuse parsing thinking this is a nested type\n    public long quantity()","sourceCodeStart":95,"sourceCodeEnd":131,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/config/DurationSpec.java#L95-L131","documentation":"validateQuantity rejects durations that, converted to the spec's minimum unit, reach or exceed the configured upper bound (max). The message reports the largest allowed value (max-1) in the min unit. This bounds duration-typed config properties to prevent unbounded/extreme values.","triggerScenarios":"Setting a duration property to a value that overflows the spec's maximum, e.g. '3650d' on a spec capped at 30 days, or a huge value in ms like '999999999999ms'.","commonSituations":"Disabling-style attempts with extremely large durations; misreading the unit so '30d' becomes 30 days when ms was intended; copy-pasting values from other systems with different caps.","solutions":["Reduce the value below the printed maximum (max-1) in the shown unit","Convert to a larger unit if appropriate (e.g. 720h instead of huge ms numbers)","Check the spec's javadoc/source for the intended maximum for that property","If a 'disabled' semantic is needed, use the property's documented disable value (often 0 or -1) instead of a huge duration"],"exampleFix":"// before (max 30 days)\nguardrail_window = \"3650d\";\n// after\nguardrail_window = \"29d\";","handlingStrategy":"validation","validationCode":"static void checkMax(String v, long maxInMinUnit, TimeUnit minUnit) {\n    long qty = Long.parseLong(v.replaceAll(\"[a-zµ]+$\", \"\"));\n    TimeUnit u = symbolToEnum(v.replaceAll(\"^\\\\d+\", \"\"));\n    if (minUnit.convert(qty, u) >= maxInMinUnit)\n        throw new IllegalArgumentException(\"Duration exceeds cap: \" + v);\n}","typeGuard":null,"tryCatchPattern":"try {\n    spec = new MyDurationSpec(\"3650d\");\n} catch (IllegalArgumentException e) {\n    logger.error(\"Duration over max: {}\", e.getMessage());\n}","preventionTips":["Read the spec's documented maximum before setting large values","Use the property's documented disable value instead of huge durations","Sanity-check unit magnitudes when converting (d vs ms)"],"tags":["configuration","duration","bounds"],"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-14T16:17:12.679Z"}