{"record":{"id":"c49312f3a6816656","repo":"apache/cassandra","slug":"invalid-value-d-for-s-negative-values-are-not-a","errorCode":null,"errorMessage":"Invalid value %d for %s: negative values are not allowed, outside of -1 which disables the guardrail","messagePattern":"Invalid value (.+?) for (.+?): negative values are not allowed, outside of -1 which disables the guardrail","errorType":"validation","errorClass":"java.lang.IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/config/GuardrailsOptions.java","lineNumber":1500,"sourceCode":"        {\n            setter.accept(newValue);\n            logger.info(\"Updated {} from {} to {}\", propertyName, oldValue, newValue);\n        }\n    }\n\n    private static void validatePositiveNumeric(long value, long maxValue, String name)\n    {\n        if (value == -1)\n            return;\n\n        if (value > maxValue)\n            throw new IllegalArgumentException(format(\"Invalid value %d for %s: maximum allowed value is %d\",\n                                                      value, name, maxValue));\n\n        // Zero is a valid threshold, meaning \"any value above zero triggers the guardrail\". \n        // We allow -1 as a general \"disabling\" flag, but reject anything lower to avoid mistakes.\n        if (value < 0)\n            throw new IllegalArgumentException(format(\"Invalid value %d for %s: negative values are not allowed, \" +\n                                                      \"outside of -1 which disables the guardrail\", value, name));\n    }\n\n    private static void validatePercentage(long value, String name)\n    {\n        validatePositiveNumeric(value, 100, name);\n    }\n\n    private static void validatePercentageThreshold(int warn, int fail, String name)\n    {\n        validatePercentage(warn, name + \"_warn_threshold\");\n        validatePercentage(fail, name + \"_fail_threshold\");\n        validateWarnLowerThanFail(warn, fail, name);\n    }\n\n    private static void validateMaxIntThreshold(int warn, int fail, String name)\n    {\n        validatePositiveNumeric(warn, Integer.MAX_VALUE, name + \"_warn_threshold\");","sourceCodeStart":1482,"sourceCodeEnd":1518,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/config/GuardrailsOptions.java#L1482-L1518","documentation":"GuardrailsOptions.validatePositiveNumeric() validates numeric guardrail thresholds in cassandra.yaml (or via live guardrail updates). Any value below 0 other than the special -1 'disabled' sentinel is rejected with this IllegalArgumentException. This includes 0 being valid (any value above zero triggers the guardrail), so only values <= -2 trigger it.","triggerScenarios":"Setting any guardrail threshold such as read_before_write_consistency_levels_warn_threshold, partition_size_in_mb thresholds, or percentage thresholds to a negative value other than -1, e.g. cassandra.yaml containing 'some_guardrail_warn_threshold: -50', or passing a negative value through Config#setGuardrails / guardrail setter at startup or via a config update.","commonSituations":"Operators hand-editing cassandra.yaml and using -1, -2 or other negatives intending to 'disable' or 'lower' a guardrail; scripts templating thresholds with uninitialized negative variables; copying a -1 disable flag but adding an offset; upgrading from configs where -1 semantics differed.","solutions":["Change the offending threshold to a non-negative value (0 is valid and means 'any value above zero triggers').","If the intent was to disable the guardrail, set the value to exactly -1.","If the value came from a script/templating variable, fix the variable source so it produces a valid integer (>= 0 or -1)."],"exampleFix":"// cassandra.yaml before\nread_before_write_consistency_levels_warn_threshold: -5\n// after (disable)\nread_before_write_consistency_levels_warn_threshold: -1\n// after (valid threshold)\nread_before_write_consistency_levels_warn_threshold: 0","handlingStrategy":"validation","validationCode":"long v = configuredThreshold;\nif (v < 0 && v != -1) throw new IllegalArgumentException(\"threshold must be >= 0 or exactly -1 to disable, got \" + v);","typeGuard":null,"tryCatchPattern":"try { applyGuardrailConfig(cfg); } catch (IllegalArgumentException e) { log.error(\"Bad guardrail threshold: {}\", e.getMessage()); throw e; }","preventionTips":["Remember: 0 is a valid threshold (triggers above zero); -1 disables; anything else negative is rejected.","Lint cassandra.yaml guardrail values in CI before deployment.","Source threshold values from constants, not ad-hoc script variables."],"tags":["config","validation","guardrails","cassandra"],"backgroundTag":"invalid-config-value","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}