{"record":{"id":"025f6471a4b824ab","repo":"apache/cassandra","slug":"invalid-data-rate-s-s-it-shouldn-t-be-more-tha","errorCode":null,"errorMessage":"Invalid data rate: %s %s. It shouldn't be more than %d in %s","messagePattern":"Invalid data rate: (.+?) (.+?)\\. It shouldn't be more than (.+?) in (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/config/DataRateSpec.java","lineNumber":90,"sourceCode":"\n        validateQuantity(quantity, unit, minUnit, max);\n    }\n\n    private static void validateQuantity(String value, double quantity, DataRateUnit unit, DataRateUnit minUnit, long max)\n    {\n        // negatives are not allowed by the regex pattern\n        if (minUnit.convert(quantity, unit) >= max)\n            throw new IllegalArgumentException(\"Invalid data rate: \" + value + \". It shouldn't be more than \" +\n                                             (max - 1) + \" in \" + toLowerCaseLocalized(minUnit.name()));\n    }\n\n    private static void validateQuantity(double quantity, DataRateUnit unit, DataRateUnit minUnit, long max)\n    {\n        if (quantity < 0)\n            throw new IllegalArgumentException(\"Invalid data rate: value must be non-negative\");\n\n        if (minUnit.convert(quantity, unit) >= max)\n            throw new IllegalArgumentException(String.format(\"Invalid data rate: %s %s. It shouldn't be more than %d in %s\",\n                                                       quantity, toLowerCaseLocalized(unit.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 rate unit assigned.\n     */\n    public DataRateUnit unit()\n    {\n        return unit;\n    }\n\n    /**\n     * @return the data rate quantity.\n     */","sourceCodeStart":72,"sourceCodeEnd":108,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/config/DataRateSpec.java#L72-L108","documentation":"The double-quantity overload of validateQuantity also enforces an upper bound: if the quantity converted into the minimum unit reaches the configured max, this formatted IllegalArgumentException is thrown, echoing the quantity, its unit, and the maximum allowed (max-1) in the minimum unit.","triggerScenarios":"Programmatic construction of a DataRateSpec (e.g. new DataRateSpec.DataRate(quantity, unit)) where quantity converted to the min unit is >= max, such as Long.MAX_VALUE bytes/s.","commonSituations":"Overflow-prone arithmetic producing huge rates (multiplying before unit conversion); passing Long.MAX_VALUE or Double.MAX_VALUE as a 'disable limit' sentinel; fuzz/property tests generating extreme values.","solutions":["Cap the quantity so its conversion into the minimum unit is below the printed maximum","Convert to the smallest unit BEFORE arithmetic to avoid multiplication overflow","Replace sentinel maxima with real bounded rates (e.g. 1 PiB/s equivalent)","Guard the call site with a range check against the documented maximum"],"exampleFix":"// before\nlong rate = megabits * 125_000L; // may exceed bound\nDataRateSpec.DataRate r = new DataRateSpec.DataRate(rate, DataRateUnit.BYTES_PER_SECOND);\n// after\nlong rate = Math.min(megabits * 125_000L, MAX_ALLOWED_BYTES_PER_SECOND);\nDataRateSpec.DataRate r = new DataRateSpec.DataRate(rate, DataRateUnit.BYTES_PER_SECOND);","handlingStrategy":"validation","validationCode":"if (minUnit.convert(quantity, unit) >= MAX)\n    throw new IllegalArgumentException(\"Rate \" + quantity + \" \" + unit + \" exceeds max \" + (MAX - 1) + \" in \" + minUnit);","typeGuard":null,"tryCatchPattern":"try {\n    rate = new DataRateSpec.DataRate(quantity, unit);\n} catch (IllegalArgumentException e) {\n    logger.error(\"Rate exceeds maximum allowed\", e);\n    rate = new DataRateSpec.DataRate(MAX_SAFE, unit);\n}","preventionTips":["Perform unit conversion before multiplication to avoid long overflow","Never pass Long.MAX_VALUE/Double.MAX_VALUE as rate sentinels","Bound-check generated or fuzzed values before constructing specs"],"tags":["configuration","range","overflow"],"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"}