{"record":{"id":"851f113308998f36","repo":"apache/cassandra","slug":"invalid-data-storage-d-s-it-shouldn-t-be-more","errorCode":null,"errorMessage":"Invalid data storage: %d %s. It shouldn't be more than %d in %s","messagePattern":"Invalid data storage: (.+?) (.+?)\\. It shouldn't be more than (.+?) in (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/config/DataStorageSpec.java","lineNumber":113,"sourceCode":"        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)\n    {\n        if (quantity < 0)\n            throw new IllegalArgumentException(\"Invalid data storage: value must be non-negative\");\n\n        if (minUnit.convert(quantity, sourceUnit) >= max)\n            throw new IllegalArgumentException(String.format(\"Invalid data storage: %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    /**\n     * @return the data storage quantity.\n     */\n    public long quantity()\n    {\n        return quantity;\n    }\n\n    /**\n     * @return the data storage unit.\n     */","sourceCodeStart":95,"sourceCodeEnd":131,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/config/DataStorageSpec.java#L95-L131","documentation":"This is the long-constructor variant of the max-bound check in DataStorageSpec.validateQuantity: when the quantity converted to the spec's minimum unit reaches the maximum bound, an IllegalArgumentException is thrown with a formatted message showing the value, source unit, and allowed maximum.","triggerScenarios":"Calling a DataStorageSpec long constructor with a quantity whose normalized value (in minUnit) is >= max, e.g. new DataStorageSpec.DataStorageBytesBound(Long.MAX_VALUE) — which is the MAX bound itself and thus rejected.","commonSituations":"Programmatic config builders that pass Long.MAX_VALUE as 'unlimited', size arithmetic overflow, or tests using extreme sentinel values.","solutions":["Pass a value below the documented maximum for the setting","Replace Long.MAX_VALUE sentinels with a realistic bounded size","If the value is computed, check the intermediate math for overflow"],"exampleFix":"// before\nnew DataStorageSpec.DataStorageBytesBound(Long.MAX_VALUE)\n// after\nnew DataStorageSpec.DataStorageBytesBound(Long.MAX_VALUE - 1)","handlingStrategy":"validation","validationCode":"if (quantity == Long.MAX_VALUE || quantity < 0) throw new IllegalArgumentException(\"quantity out of representable range\");","typeGuard":null,"tryCatchPattern":"try { spec = new DataStorageSpec.DataStorageBytesBound(v); } catch (IllegalArgumentException e) { spec = defaultSpec; }","preventionTips":["Never pass Long.MAX_VALUE as a 'max' storage size","Add range assertions before constructing specs from computed values","Test config builders with boundary values"],"tags":["cassandra","config","data-storage-spec","value-out-of-range"],"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"}