{"record":{"id":"9369f259ead22f61","repo":"apache/cassandra","slug":"invalid-duration-s-accepted-units-s-where-case","errorCode":null,"errorMessage":"Invalid duration: %s Accepted units:%s where case matters and only non-negative values.","messagePattern":"Invalid duration: (.+?) Accepted units:(.+?) where case matters and only non-negative values\\.","errorType":"validation","errorClass":"java.lang.IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/config/DurationSpec.java","lineNumber":83,"sourceCode":"    private DurationSpec(double quantity, TimeUnit unit, TimeUnit minUnit, long max)\n    {\n        this(Math.round(quantity), unit, minUnit, max);\n    }\n\n    private DurationSpec(String value, TimeUnit minUnit)\n    {\n        Matcher matcher = UNITS_PATTERN.matcher(value);\n\n        if (matcher.find())\n        {\n            quantity = Long.parseLong(matcher.group(1));\n            unit = fromSymbol(matcher.group(2));\n\n            // this constructor is used only by extended classes for min unit; upper bound and min unit are guarded there accordingly\n        }\n        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","sourceCodeStart":65,"sourceCodeEnd":101,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/config/DurationSpec.java#L65-L101","documentation":"DurationSpec's string constructor parses values like '100ms' with a regex anchored to a set of accepted units (>= minUnit). If the value does not match (bad unit, negative number, whitespace, missing unit), an IllegalArgumentException with the accepted units list is thrown. Case matters: '100MS' or '100Ms' is rejected.","triggerScenarios":"Setting any duration-typed cassandra.yaml/config property (e.g. read_request_timeout, gc_grace_seconds-like specs) with a value whose unit symbol is unknown, wrong case, negative, malformed, or below the minUnit allowed for that property.","commonSituations":"Typo in unit ('duries', '100sec'), uppercase units ('100S'), negative durations ('-5s'), missing unit ('100'), or using a unit finer than the property's minimum (e.g. 'ns' where 'ms' is the floor).","solutions":["Rewrite the value with a correct, lowercase unit symbol (d, h, m, s, ms, us, µs, ns) allowed for that property","Remove signs/whitespace: only non-negative plain numbers plus unit are accepted","Check the property's documentation for its minimum accepted unit","If set programmatically, use the long-valued constructor with the intended TimeUnit instead of a string"],"exampleFix":"// before\nread_request_timeout = \"5000MS\";\n// after\nread_request_timeout = \"5000ms\";","handlingStrategy":"validation","validationCode":"private static final Pattern DURATION = Pattern.compile(\"^(\\\\d+)(d|h|m|s|ms|us|µs|ns)$\");\nstatic void checkDuration(String v) {\n    if (v == null || !DURATION.matcher(v.trim()).matches())\n        throw new IllegalArgumentException(\"Invalid duration: \" + v);\n}","typeGuard":null,"tryCatchPattern":"try {\n    config.setReadRequestTimeout(\"5000ms\");\n} catch (IllegalArgumentException e) {\n    logger.error(\"Duration config rejected: {}\", e.getMessage());\n}","preventionTips":["Always use lowercase unit symbols","Never prefix durations with a sign","Include the unit; never pass a bare number string","Validate durations at config-load time with a regex pre-check"],"tags":["configuration","duration","validation"],"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"}