{"record":{"id":"e82c8e5b2898a7be","repo":"apache/cassandra","slug":"invalid-data-storage-s-accepted-units-s","errorCode":null,"errorMessage":"Invalid data storage: %s Accepted units:%s","messagePattern":"Invalid data storage: (.+?) Accepted units:(.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/config/DataStorageSpec.java","lineNumber":89,"sourceCode":"        else\n        {\n            throw new IllegalArgumentException(\"Invalid data storage: \" + value + \" Accepted units:\" + acceptedUnits(minUnit) +\n                                               \" where case matters and only non-negative values are accepted\");\n        }\n    }\n\n    private DataStorageSpec(String value, DataStorageUnit 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(DataStorageUnit sourceUnit, DataStorageUnit minUnit, String value)\n    {\n        if (sourceUnit.compareTo(minUnit) < 0)\n            throw new IllegalArgumentException(String.format(\"Invalid data storage: %s Accepted units:%s\", value, acceptedUnits(minUnit)));\n    }\n\n    private static String acceptedUnits(DataStorageUnit minUnit)\n    {\n        DataStorageUnit[] units = DataStorageUnit.values();\n        return Arrays.toString(Arrays.copyOfRange(units, minUnit.ordinal(), units.length));\n    }\n\n    private static void validateQuantity(String value, long quantity, DataStorageUnit sourceUnit, DataStorageUnit 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 data storage: \" + value + \". It shouldn't be more than \" +\n                                               (max - 1) + \" in \" + toLowerCaseLocalized(minUnit.name()));\n    }\n\n    private static void validateQuantity(long quantity, DataStorageUnit sourceUnit, DataStorageUnit minUnit, long max)","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/config/DataStorageSpec.java#L71-L107","documentation":"validateMinUnit checks that the unit parsed from a DataStorageSpec value is not smaller than the required minimum unit for that spec subclass. If the source unit compares below the min unit (ordinal-wise), it throws this IllegalArgumentException listing only the acceptable units.","triggerScenarios":"Constructing a bounded/extended DataStorageSpec (e.g. DataStorageSpec.LongStorageBound) from a string expressed in a unit below the required min unit, such as '512B' or '10KiB' where the bound requires MiB or larger.","commonSituations":"Programmatic config building where subclasses impose minimum units; YAML migration code reusing a generic storage string for a bound type that needs a larger unit; test fixtures with tiny values.","solutions":["Express the value in a unit at or above the min unit (e.g. convert 512KiB to 1MiB if the min unit is MiB)","Read acceptedUnits from the message and pick the smallest listed unit","Use the numeric double-based constructor with an explicit unit when you control the unit programmatically","Add a pre-parse check comparing DataStorageUnit ordinals against the bound's minimum"],"exampleFix":"// before\nDataStorageSpec.LongStorageBound b = new DataStorageSpec.LongStorageBound(\"512KiB\");\n// after\nDataStorageSpec.LongStorageBound b = new DataStorageSpec.LongStorageBound(\"1MiB\");","handlingStrategy":"validation","validationCode":"DataStorageSpec.DataStorageUnit src = DataStorageSpec.DataStorageUnit.fromSymbol(unitToken);\nif (src.compareTo(MIN_UNIT) < 0)\n    throw new IllegalArgumentException(\"Unit \" + unitToken + \" is below the minimum \" + MIN_UNIT);","typeGuard":null,"tryCatchPattern":"try {\n    bound = new DataStorageSpec.LongStorageBound(value);\n} catch (IllegalArgumentException e) {\n    logger.error(\"Storage unit below required minimum for bound: \" + value, e);\n    bound = new DataStorageSpec.LongStorageBound(convertToMinUnitOrAbove(value));\n}","preventionTips":["Check each bound subclass's minimum unit before formatting its value","Convert small-unit values (B, KiB) up to the minimum unit programmatically","Prefer the numeric constructors with explicit units in code"],"tags":["configuration","units","validation"],"backgroundTag":"invalid-config-value","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"}