{"record":{"id":"eb6ba6aacedfa193","repo":"apache/cassandra","slug":"invalid-duration-s-accepted-units-s","errorCode":null,"errorMessage":"Invalid duration: %s Accepted units:%s","messagePattern":"Invalid duration: (.+?) Accepted units:(.+?)","errorType":"validation","errorClass":"java.lang.IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/config/DurationSpec.java","lineNumber":99,"sourceCode":"        else\n        {\n            throw new IllegalArgumentException(\"Invalid duration: \" + value + \" Accepted units:\" + acceptedUnits(minUnit) +\n                                               \" where case matters and only non-negative values.\");\n        }\n    }\n\n    private DurationSpec(String value, TimeUnit minUnit, long max)\n    {\n        this(value, minUnit);\n\n        validateMinUnit(unit, minUnit, value);\n        validateQuantity(value, quantity(), unit(), minUnit, max);\n    }\n\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)","sourceCodeStart":81,"sourceCodeEnd":117,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/config/DurationSpec.java#L81-L117","documentation":"validateMinUnit rejects a parsed duration whose unit is finer than the minimum unit permitted for that spec (e.g. a seconds-based spec given '500ms'). The value format was otherwise valid, but the unit granularity is not accepted. Thrown as IllegalArgumentException with the accepted units list.","triggerScenarios":"Configuring a DurationSpec-typed property whose minUnit is e.g. MILLISECONDS with a value in 'us' or 'ns', such as a property declared with minUnit ms receiving '10us'.","commonSituations":"Copying a duration value between properties with different minimum units; downsizing timeouts to sub-millisecond precision where the spec disallows it.","solutions":["Convert the value to the minimum allowed unit (e.g. 10us -> 0ms is not possible; use a larger value or a coarser unit)","Check the spec class definition to see the minUnit enforced by that property's constructor","Use the smallest allowed unit symbol listed in the error message"],"exampleFix":"// before (minUnit ms)\ncoordinator_write_size = \"10us\";\n// after\ncoordinator_write_size = \"1ms\";","handlingStrategy":"validation","validationCode":"static void checkMinUnit(String v, TimeUnit minUnit) {\n    Matcher m = DURATION.matcher(v.trim());\n    if (m.matches() && TimeUnit.valueOf(symbolToEnum(m.group(2))).compareTo(minUnit) < 0)\n        throw new IllegalArgumentException(\"Unit too fine for this spec: \" + v);\n}","typeGuard":null,"tryCatchPattern":"try {\n    new MyDurationSpec(\"10us\");\n} catch (IllegalArgumentException e) {\n    logger.error(\"Unit below minimum allowed: {}\", e.getMessage());\n}","preventionTips":["Know each property's minimum unit before configuring","Round sub-min-unit values up to the minimum unit","Avoid copying duration strings between differently-typed properties"],"tags":["configuration","duration","unit-conversion"],"backgroundTag":"invalid-duration-format","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"}