apache/cassandra · error · IllegalArgumentException
Latency must be specified in terms of milliseconds (with…
Error message
Latency must be specified in terms of milliseconds (with 'ms' suffix)
What it means
ArtificialLatency.parseNanos parses a latency string that must be expressed in milliseconds with an explicit 'ms' suffix (e.g. "5ms"). If the string does not end with 'ms', an IllegalArgumentException is thrown before any numeric parsing.
Solutions
- Append the 'ms' suffix to the latency value, e.g. "100ms"
- Use lowercase 'ms' with no whitespace between number and unit
- Convert other units to milliseconds before configuring (e.g. "1000ms" instead of "1s")
- Check the cassandra.yaml value for artificial latency settings and ensure every entry ends in 'ms'
Example fix
// before
ArtificialLatency.setArtificialLatencies("100");
// after
ArtificialLatency.setArtificialLatencies("100ms");
Defensive patterns
Strategy: validation
Validate before calling
function validateLatency(latency) {
if (!/^\d+ms$/.test(latency)) throw new Error("Latency must be like '100ms': " + latency);
} Type guard
static boolean isValidLatency(String s) { return s != null && s.matches("\\d+ms"); } Try / catch
try { ArtificialLatency.setArtificialLatencies(value); }
catch (IllegalArgumentException e) { logger.error("Bad latency format: {}", value); } Prevention
- Always include the lowercase 'ms' suffix on latency values
- No whitespace between number and unit
- Convert other units to milliseconds before configuring
When it happens
Trigger: Calling ArtificialLatency.setArtificialLatencies (or the cassandra.yaml/advanced config artificial_latency setting, or nanos()) with a latency value lacking the 'ms' suffix, e.g. "100" or "100us" or "1s".
Common situations: Configuring test_latency / artificial latency settings without units; migrating configs from formats that used raw numbers; typos like "100 MS" (uppercase or space) which also fail endsWith("ms").
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
- Artificial latency limit is
- Commit log position must be given as
- Invalid modifier specification
- Unsupported format " + formatString + " supported formats…
- A CQL blob string must start with "0x"
AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10).
Data as JSON: /api/errors/e6d497c6831d69f2.
Report an issue: GitHub.
Appendix: source
Thrown at src/java/org/apache/cassandra/net/ArtificialLatency.java:288
}
}
private void drainIn()
{
for (Delayed delayed = in.poll(); delayed != null ; delayed = in.poll())
out.add(delayed);
}
}
public static String getArtificialLatencies()
{
return artificialLatencies;
}
private static long parseNanos(String latency)
{
if (!latency.endsWith("ms"))
throw new IllegalArgumentException("Latency must be specified in terms of milliseconds (with 'ms' suffix)");
return TimeUnit.MILLISECONDS.toNanos(Long.parseLong(latency.substring(0, latency.length() - 2)));
}
public static void setArtificialLatencies(String latencies)
{
setArtificialLatencies(latencies, parseNanos(ARTIFICIAL_LATENCY_LIMIT.getString()));
}
public static void unsafeSetArtificialLatencies(String latencies)
{
setArtificialLatencies(latencies, Long.MAX_VALUE);
}
private static synchronized void setArtificialLatencies(String latencies, long nanoLimit)
{
if (latencies.indexOf(',') < 0)
{View on GitHub (pinned to 88fd0f6a0e)