{"record":{"id":"f9d8d50c209e8746","repo":"alibaba/nacos","slug":"distrothreshold-can-not-be-zero-or-negative-thre","errorCode":null,"errorMessage":"distroThreshold can not be zero or negative: {threshold}","messagePattern":"distroThreshold can not be zero or negative: (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":400,"severity":"warning","filePath":"naming/src/main/java/com/alibaba/nacos/naming/misc/SwitchManager.java","lineNumber":119,"sourceCode":"    /**\n     * Update switch information.\n     *\n     * @param entry item entry of switch, {@link SwitchEntry}\n     * @param value switch value\n     * @param debug whether debug\n     * @throws Exception exception\n     */\n    public void update(String entry, String value, boolean debug) throws Exception {\n        \n        this.requestLock.lock();\n        try {\n            \n            SwitchDomain tempSwitchDomain = this.switchDomain.clone();\n            \n            if (entry.equals(SwitchEntry.DISTRO_THRESHOLD)) {\n                float threshold = Float.parseFloat(value);\n                if (threshold <= 0) {\n                    throw new IllegalArgumentException(\n                        \"distroThreshold can not be zero or negative: \" + threshold);\n                }\n                tempSwitchDomain.setDistroThreshold(threshold);\n            }\n            \n            if (entry.equals(SwitchEntry.CLIENT_BEAT_INTERVAL)) {\n                long clientBeatInterval = Long.parseLong(value);\n                tempSwitchDomain.setClientBeatInterval(clientBeatInterval);\n            }\n            \n            if (entry.equals(SwitchEntry.PUSH_VERSION)) {\n                \n                String[] parts = value.split(\":\");\n                if (parts.length < 2) {\n                    throw new IllegalArgumentException(\n                        \"illegal format, must be 'type:version', but got: \" + value);\n                }\n                String type = parts[0];","sourceCodeStart":101,"sourceCodeEnd":137,"githubUrl":"https://github.com/alibaba/nacos/blob/9b989acdf181d00898f2e8839257bb2b2a3cefe3/naming/src/main/java/com/alibaba/nacos/naming/misc/SwitchManager.java#L101-L137","documentation":"Thrown by SwitchManager.update when the 'distroThreshold' switch entry is parsed as a float and the result is <= 0. The exception is an IllegalArgumentException (not a NacosException), raised during a switch-update operation on the cloned SwitchDomain. The Distro consistency threshold must be strictly positive (it controls the fraction of healthy instances below which Distro protects a service).","triggerScenarios":"Calling the switch-update API (or SwitchManager.update directly) with entry='distroThreshold' and a value of '0', a negative number like '-0.5', or a non-numeric string that Float.parseFloat rejects (though that would throw NumberFormatException first). The explicit <= 0 guard catches valid-but-invalid floats like 0.0f or -1.0f.","commonSituations":"Operator accidentally sets distroThreshold to 0 when trying to disable health protection. Misconfigured automation passing an empty or zero string. Attempting to tune the protection threshold without understanding its semantics.","solutions":["Provide a positive float between 0.0 (exclusive) and 1.0, e.g. '0.5' or '0.85' (typical production value).","Validate the input string is a valid positive float before calling update.","Review the Distro protection semantics — setting it too low disables instance protection; it should never be zero."],"exampleFix":"// before\nswitchManager.update(\"distroThreshold\", \"0\", false);\n\n// after\nswitchManager.update(\"distroThreshold\", \"0.5\", false);","handlingStrategy":"validation","validationCode":"String value = \"0.5\"; // from operator input\nfloat threshold = Float.parseFloat(value);\nif (threshold <= 0) {\n    throw new IllegalArgumentException(\"distroThreshold must be > 0\");\n}\nswitchManager.update(\"distroThreshold\", value, false);","typeGuard":null,"tryCatchPattern":"try {\n    switchManager.update(\"distroThreshold\", value, false);\n} catch (IllegalArgumentException e) {\n    // invalid threshold — log and reject the operation\n    logger.error(\"Invalid distroThreshold: {}\", value);\n}","preventionTips":["Validate the distroThreshold is a positive float (typically 0.0–1.0) before calling update.","Never set distroThreshold to 0 — it disables Distro health protection.","Use configuration management tools to prevent zero/negative values."],"tags":["naming","switch","distro","threshold","validation","configuration"],"backgroundTag":null,"analyzedSha":"9b989acdf181d00898f2e8839257bb2b2a3cefe3","analyzedAt":"2026-08-14T07:17:31.569Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}