apache/cassandra · error · IllegalArgumentException

Invalid data rate: %s %s. It shouldn't be more than %d in %s

Error message

Invalid data rate: %s %s. It shouldn't be more than %d in %s

What it means

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.

Source

Thrown at src/java/org/apache/cassandra/config/DataRateSpec.java:90

        validateQuantity(quantity, unit, minUnit, max);
    }

    private static void validateQuantity(String value, double quantity, DataRateUnit unit, DataRateUnit minUnit, long max)
    {
        // negatives are not allowed by the regex pattern
        if (minUnit.convert(quantity, unit) >= max)
            throw new IllegalArgumentException("Invalid data rate: " + value + ". It shouldn't be more than " +
                                             (max - 1) + " in " + toLowerCaseLocalized(minUnit.name()));
    }

    private static void validateQuantity(double quantity, DataRateUnit unit, DataRateUnit minUnit, long max)
    {
        if (quantity < 0)
            throw new IllegalArgumentException("Invalid data rate: value must be non-negative");

        if (minUnit.convert(quantity, unit) >= max)
            throw new IllegalArgumentException(String.format("Invalid data rate: %s %s. It shouldn't be more than %d in %s",
                                                       quantity, toLowerCaseLocalized(unit.name()),
                                                       max - 1, toLowerCaseLocalized(minUnit.name())));
    }

    // get vs no-get prefix is not consistent in the code base, but for classes involved with config parsing, it is
    // imporant to be explicit about get/set as this changes how parsing is done; this class is a data-type, so is
    // not nested, having get/set can confuse parsing thinking this is a nested type
    /**
     * @return the data rate unit assigned.
     */
    public DataRateUnit unit()
    {
        return unit;
    }

    /**
     * @return the data rate quantity.
     */

View on GitHub (pinned to 88fd0f6a0e)

Solutions

  1. Cap the quantity so its conversion into the minimum unit is below the printed maximum
  2. Convert to the smallest unit BEFORE arithmetic to avoid multiplication overflow
  3. Replace sentinel maxima with real bounded rates (e.g. 1 PiB/s equivalent)
  4. Guard the call site with a range check against the documented maximum

Example fix

// before
long rate = megabits * 125_000L; // may exceed bound
DataRateSpec.DataRate r = new DataRateSpec.DataRate(rate, DataRateUnit.BYTES_PER_SECOND);
// after
long rate = Math.min(megabits * 125_000L, MAX_ALLOWED_BYTES_PER_SECOND);
DataRateSpec.DataRate r = new DataRateSpec.DataRate(rate, DataRateUnit.BYTES_PER_SECOND);
Defensive patterns

Strategy: validation

Validate before calling

if (minUnit.convert(quantity, unit) >= MAX)
    throw new IllegalArgumentException("Rate " + quantity + " " + unit + " exceeds max " + (MAX - 1) + " in " + minUnit);

Try / catch

try {
    rate = new DataRateSpec.DataRate(quantity, unit);
} catch (IllegalArgumentException e) {
    logger.error("Rate exceeds maximum allowed", e);
    rate = new DataRateSpec.DataRate(MAX_SAFE, unit);
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.

Related errors


AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10). Data as JSON: /api/errors/025f6471a4b824ab. Report an issue: GitHub.