apache/cassandra · error · NumberFormatException
does not end in unit
Error message
does not end in unit
What it means
FBUtilities.parseHumanReadable parses a human-readable quantity like '10GB' into a numeric value. This NumberFormatException is thrown when the input string does not end with the expected unit suffix (e.g. 'ms', 'KB'). It indicates the value string is missing or has a wrong unit suffix.
Solutions
- Append the required unit to the value, e.g. change 512 to 512KB
- Fix the unit spelling/case to exactly match the expected suffix
- Strip whitespace around the configured value before parsing
- Change the caller to pass null for unit if the unit should be optional
Example fix
// before: parseHumanReadable(configValue, null, "KiB") where configValue = "1024" // after: String configValue = "1024KiB"; // or drop the unit argument
Defensive patterns
Strategy: validation
Validate before calling
if (value != null && unit != null && !value.trim().endsWith(unit)) throw new IllegalArgumentException("value must end with " + unit); Try / catch
try { return FBUtilities.parseHumanReadable(s, null, "KB"); } catch (NumberFormatException e) { throw new ConfigurationException("Invalid quantity '" + s + "': " + e.getMessage()); } Prevention
- Always include the required unit suffix in config values
- Trim whitespace from config strings before parsing
- Wrap parsing in a helper that reports the config key name
When it happens
Trigger: Calling FBUtilities.parseHumanReadable(datum, separator, unit) with a datum whose text does not end with the supplied unit, e.g. parseHumanReadable("10", null, "KB") or "10Mib " with trailing whitespace where unit "KB" is required.
Common situations: Users omit the unit in cassandra.yaml values parsed with a required unit (e.g. column_index_size_in_kb style settings), or include a wrong/misspelled unit.
Understand the failure class
Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.
Related errors
- Commit log position must be given as
- could not parse update query
- does not match
- Invalid ip address from input=
- Invalid modifier specification
AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10).
Data as JSON: /api/errors/9e172df73a81374b.
Report an issue: GitHub.
Appendix: source
Thrown at src/java/org/apache/cassandra/utils/FBUtilities.java:1117
}
/**
* Parse a human-readable value printed using one of the methods above. Understands both binary and decimal
* modifiers, as well as decimal exponents using the E notation and binary exponents using *2^e.
*
* @param datum The human-readable number.
* @param separator Expected separator, null to accept any amount of whitespace.
* @param unit Expected unit. If null, the method will accept any string as unit, i.e. it will parse the number
* at the start of the supplied string and ignore any remainder.
* @return The parsed value.
*/
public static double parseHumanReadable(String datum, String separator, String unit)
{
int end = datum.length();
if (unit != null)
{
if (!datum.endsWith(unit))
throw new NumberFormatException(datum + " does not end in unit " + unit);
end -= unit.length();
}
Matcher m = BASE_NUMBER_PATTERN.matcher(datum);
m.region(0, end);
if (!m.lookingAt())
throw new NumberFormatException();
double v = Double.parseDouble(m.group(0));
int pos = m.end();
if (m.group(2) == null) // possible binary exponent, parse
{
m = BINARY_EXPONENT.matcher(datum);
m.region(pos, end);
if (m.lookingAt())
{
int power = Integer.parseInt(m.group(1));
v = Math.scalb(v, power);View on GitHub (pinned to 88fd0f6a0e)