{"record":{"id":"5e844d54d63dd8f1","repo":"apache/cassandra","slug":"cannot-set-field-to-negative-value","errorCode":null,"errorMessage":"Cannot set '\" + field + \"' to negative value\"","messagePattern":"Cannot set '\" \\+ field \\+ \"' to negative value\"","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/db/virtual/AccordDebugKeyspace.java","lineNumber":2497,"sourceCode":"\n    private static BucketMode checkBucketMode(Object value)\n    {\n        try { return AccordTracing.BucketMode.valueOf(LocalizeString.toUpperCaseLocalized((String)value, Locale.ENGLISH)); }\n        catch (IllegalArgumentException | NullPointerException e)\n        {\n            throw new InvalidRequestException(\"Unknown bucket_mode '\" + value + '\\'');\n        }\n\n    }\n\n    private static int checkNonNegative(Object value, String field, int ifNull)\n    {\n        if (value == null)\n            return ifNull;\n\n        int v = (Integer)value;\n        if (v < 0)\n            throw new InvalidRequestException(\"Cannot set '\" + field + \"' to negative value\");\n        return v;\n    }\n\n    private static float checkChance(Object value, String field)\n    {\n        if (value == null)\n            return 1.0f;\n\n        float v = (Float)value;\n        if (v <= 0 || v > 1.0f)\n            throw new InvalidRequestException(\"Cannot set '\" + field + \"' to value outside the range (0..1]\");\n        return v;\n    }\n\n    private static <T extends Enum<T>> Set<String> toStrings(TinyEnumSet<T> set, IntFunction<T> lookup)\n    {\n        ImmutableSet.Builder<String> builder = ImmutableSet.builder();\n        for (T t : set.iterable(lookup))","sourceCodeStart":2479,"sourceCodeEnd":2515,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/db/virtual/AccordDebugKeyspace.java#L2479-L2515","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nUPDATE system.accord_debug SET max_commands = -1;\n// after\nUPDATE system.accord_debug SET max_commands = 0; // 0 or a positive int; omit to use the default","handlingStrategy":"validation","validationCode":"if (value != null && value < 0) throw new IllegalArgumentException(field + \" must be >= 0 (omit to use the default)\");","typeGuard":"boolean isNonNegative(Integer v) { return v == null || v >= 0; }","tryCatchPattern":"try {\n    session.execute(update);\n} catch (InvalidRequestException e) {\n    if (e.getMessage().startsWith(\"Cannot set '\") && e.getMessage().contains(\"to negative value\")) {\n        // resend with the field clamped to >= 0 or omitted\n    }\n}","preventionTips":["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"],"tags":["cassandra","cql","validation","negative-value"],"backgroundTag":"invalid-argument-value","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}