apache/cassandra · error · InvalidRequestException
Cannot set '" + field + "' to negative value"
Error message
Cannot set '" + field + "' to negative value"
What it means
checkNonNegative validates an integer debug-table field, returning a default (ifNull) when the value is absent. Setting the field to a negative integer fails validation and throws this InvalidRequestException, because the field models a count, size, or duration that cannot be negative.
Solutions
- Set the field to a non-negative value (use 0 to disable/minimize if supported)
- Omit the column entirely to get the documented default (ifNull)
- Consult the table's column comments/DESCRIBE output for the valid range
Example fix
// before UPDATE system.accord_debug SET max_commands = -1; // after UPDATE system.accord_debug SET max_commands = 0; // 0 or a positive int; omit to use the default
Defensive patterns
Strategy: validation
Validate before calling
if (value != null && value < 0) throw new IllegalArgumentException(field + " must be >= 0 (omit to use the default)");
Type guard
boolean isNonNegative(Integer v) { return v == null || v >= 0; } Try / catch
try {
session.execute(update);
} catch (InvalidRequestException e) {
if (e.getMessage().startsWith("Cannot set '") && e.getMessage().contains("to negative value")) {
// resend with the field clamped to >= 0 or omitted
}
} Prevention
- Do not use -1 as a 'disable' sentinel for these debug fields; use 0 or omit the column
- Clamp or validate all integers in scripts before building CQL
- Check column comments for valid ranges
When it happens
Trigger: An UPDATE/INSERT on an Accord debug virtual table column processed by checkNonNegative (e.g. a count/limit/period field) with a value < 0, such as SET some_field = -1.
Common situations: Trying to 'disable' a feature by setting a count/limit to -1 (a pattern that works in some other systems but not here); sign errors when parameterizing cqlsh scripts; mistaking 0 for the disable value when 0 is the correct sentinel.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- Cannot add new field
- Cannot set '" + field + "' to value outside the range…
- Column value does not satisfy value constraint for column
- Column value does not satisfy value constraint for column
- Empty value for boolean option ''
AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10).
Data as JSON: /api/errors/5e844d54d63dd8f1.
Report an issue: GitHub.
Appendix: source
Thrown at src/java/org/apache/cassandra/db/virtual/AccordDebugKeyspace.java:2497
private static BucketMode checkBucketMode(Object value)
{
try { return AccordTracing.BucketMode.valueOf(LocalizeString.toUpperCaseLocalized((String)value, Locale.ENGLISH)); }
catch (IllegalArgumentException | NullPointerException e)
{
throw new InvalidRequestException("Unknown bucket_mode '" + value + '\'');
}
}
private static int checkNonNegative(Object value, String field, int ifNull)
{
if (value == null)
return ifNull;
int v = (Integer)value;
if (v < 0)
throw new InvalidRequestException("Cannot set '" + field + "' to negative value");
return v;
}
private static float checkChance(Object value, String field)
{
if (value == null)
return 1.0f;
float v = (Float)value;
if (v <= 0 || v > 1.0f)
throw new InvalidRequestException("Cannot set '" + field + "' to value outside the range (0..1]");
return v;
}
private static <T extends Enum<T>> Set<String> toStrings(TinyEnumSet<T> set, IntFunction<T> lookup)
{
ImmutableSet.Builder<String> builder = ImmutableSet.builder();
for (T t : set.iterable(lookup))View on GitHub (pinned to 88fd0f6a0e)