{"record":{"id":"4f4e3ea8e8680b50","repo":"apache/cassandra","slug":"invalid-duration-d-s-it-shouldn-t-be-more-than","errorCode":null,"errorMessage":"Invalid duration: %d %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":123,"sourceCode":"        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()\n    {\n        return quantity;\n    }\n\n    public TimeUnit unit()\n    {\n        return unit;\n    }\n\n    public Duration toDuration()","sourceCodeStart":105,"sourceCodeEnd":141,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/config/DurationSpec.java#L105-L141","documentation":"The numeric validateQuantity overload also enforces an upper bound: if the quantity converted to minUnit is >= max, an IllegalArgumentException reports the offending value and the maximum allowed (max-1). This is the programmatic (non-string) counterpart of error 313.","triggerScenarios":"Constructing a DurationSpec subclass with a long quantity that exceeds the class's max in the given TimeUnit, e.g. new SomeDurationSpec(100_000, TimeUnit.DAYS).","commonSituations":"Unit mix-ups when passing raw longs (passing milliseconds where days expected); test fixtures with inflated values; computing a duration that overflows the spec's cap.","solutions":["Lower the quantity below max-1, or express it in a larger unit","Verify the TimeUnit argument matches the intended semantics of the number","Consult the spec class constant defining max for the allowed ceiling"],"exampleFix":"// before (max ~30 days)\nnew HintedHandoffManagerSpec(100000, TimeUnit.DAYS);\n// after\nnew HintedHandoffManagerSpec(29, TimeUnit.DAYS);","handlingStrategy":"validation","validationCode":"static void checkNumericMax(long qty, TimeUnit unit, TimeUnit minUnit, long max) {\n    if (minUnit.convert(qty, unit) >= max)\n        throw new IllegalArgumentException(\"Quantity exceeds cap of \" + (max - 1));\n}","typeGuard":null,"tryCatchPattern":"try {\n    spec = new MyDurationSpec(amount, unit);\n} catch (IllegalArgumentException e) {\n    logger.error(\"Duration out of range: {}\", e.getMessage());\n}","preventionTips":["Double-check the TimeUnit argument matches the numeric semantics","Clamp against the spec's max constant before constructing","Prefer string form ('29d') for readability over raw longs"],"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"}