{"record":{"id":"3835b497c43c4472","repo":"apache/cassandra","slug":"table-count-warn-threshold-should-be-positive-not","errorCode":null,"errorMessage":"Table count warn threshold should be positive, not {value}","messagePattern":"Table count warn threshold should be positive, not (.+?)","errorType":"validation","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/service/StorageService.java","lineNumber":5323,"sourceCode":"\n    public void setAutoOptimisePreviewRepairStreams(boolean enabled)\n    {\n        DatabaseDescriptor.setAutoOptimisePreviewRepairStreams(enabled);\n    }\n\n    /** @deprecated See CASSANDRA-17195 */\n    @Deprecated(since = \"4.1\")\n    public int getTableCountWarnThreshold()\n    {\n        return (int) Converters.TABLE_COUNT_THRESHOLD_TO_GUARDRAIL.unconvert(Guardrails.instance.getTablesWarnThreshold());\n    }\n\n    /** @deprecated See CASSANDRA-17195 */\n    @Deprecated(since = \"4.1\")\n    public void setTableCountWarnThreshold(int value)\n    {\n        if (value < 0)\n            throw new IllegalStateException(\"Table count warn threshold should be positive, not \"+value);\n        logger.info(\"Changing table count warn threshold from {} to {}\", getTableCountWarnThreshold(), value);\n        Guardrails.instance.setTablesThreshold((int) Converters.TABLE_COUNT_THRESHOLD_TO_GUARDRAIL.convert(value),\n                                               Guardrails.instance.getTablesFailThreshold());\n    }\n\n    /** @deprecated See CASSANDRA-17195 */\n    @Deprecated(since = \"4.1\")\n    public int getKeyspaceCountWarnThreshold()\n    {\n        return (int) Converters.KEYSPACE_COUNT_THRESHOLD_TO_GUARDRAIL.unconvert(Guardrails.instance.getKeyspacesWarnThreshold());\n    }\n\n    /** @deprecated See CASSANDRA-17195 */\n    @Deprecated(since = \"4.1\")\n    public void setKeyspaceCountWarnThreshold(int value)\n    {\n        if (value < 0)\n            throw new IllegalStateException(\"Keyspace count warn threshold should be positive, not \"+value);","sourceCodeStart":5305,"sourceCodeEnd":5341,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/service/StorageService.java#L5305-L5341","documentation":"setTableCountWarnThreshold() is a deprecated (CASSANDRA-17195, since 4.1) bridge from the old table-count threshold knobs to guardrails. It throws IllegalStateException for values below 0, since a warning threshold of a negative table count is meaningless.","triggerScenarios":"Calling setTableCountWarnThreshold(value) with value < 0 via JMX, nodetool, or code.","commonSituations":"Scripts computing thresholds from a percentage or delta and producing negatives; copy-pasted config defaults of -1 meaning 'unset'; migration tooling porting old yaml values.","solutions":["Pass a non-negative integer (0 effectively disables the warn threshold).","Clamp input: Math.max(0, value) before calling.","Migrate to Guardrails 'tables' configuration directly, since this setter is deprecated."],"exampleFix":"// before\nss.setTableCountWarnThreshold(-1); // throws\n// after\nss.setTableCountWarnThreshold(Math.max(0, requested)); // or use guardrails tables warn threshold","handlingStrategy":"validation","validationCode":"if (value < 0) throw new IllegalArgumentException(\"table count warn threshold must be >= 0\");\nss.setTableCountWarnThreshold(value);","typeGuard":"boolean valid = value >= 0;","tryCatchPattern":"try { ss.setTableCountWarnThreshold(v); } catch (IllegalStateException e) { log.warn(\"rejecting negative threshold {}\", v); }","preventionTips":["Reject/clamp negative values at the script boundary.","Replace -1 'unset' sentinels with 0.","Prefer the guardrails 'tables' configuration over this deprecated setter.","Sanity-check computed thresholds before applying."],"tags":["jmx","guardrails","validation","deprecated"],"backgroundTag":"value-out-of-range","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"}