{"record":{"id":"9b96ae42e1dd538c","repo":"alibaba/nacos","slug":"invalid-param-9b96ae","errorCode":"INVALID_PARAM","errorMessage":"instance format invalid: The weights range from 0.0 to 10000.0","messagePattern":"instance format invalid: The weights range from 0\\.0 to 10000\\.0","errorType":"validation","errorClass":"NacosException","httpStatus":null,"severity":"error","filePath":"naming/src/main/java/com/alibaba/nacos/naming/pojo/instance/HttpRequestInstanceBuilder.java","lineNumber":111,"sourceCode":"    private void setAttributesToBuilder(HttpServletRequest request) throws NacosException {\n        actualBuilder.setServiceName(WebUtils.required(request, CommonParams.SERVICE_NAME));\n        actualBuilder.setIp(WebUtils.required(request, \"ip\"));\n        actualBuilder.setPort(Integer.parseInt(WebUtils.required(request, \"port\")));\n        actualBuilder\n            .setHealthy(ConvertUtils.toBoolean(WebUtils.optional(request, \"healthy\", \"true\")));\n        actualBuilder.setEphemeral(ConvertUtils\n            .toBoolean(\n                WebUtils.optional(request, \"ephemeral\", String.valueOf(defaultInstanceEphemeral))));\n        setWeight(request);\n        setCluster(request);\n        setEnabled(request);\n        setMetadata(request);\n    }\n    \n    private void setWeight(HttpServletRequest request) throws NacosException {\n        double weight = Double.parseDouble(WebUtils.optional(request, \"weight\", \"1\"));\n        if (weight > Constants.MAX_WEIGHT_VALUE || weight < Constants.MIN_WEIGHT_VALUE) {\n            throw new NacosException(NacosException.INVALID_PARAM,\n                \"instance format invalid: The weights range from \" + Constants.MIN_WEIGHT_VALUE\n                    + \" to \"\n                    + Constants.MAX_WEIGHT_VALUE);\n        }\n        actualBuilder.setWeight(weight);\n    }\n    \n    private void setCluster(HttpServletRequest request) {\n        String cluster = WebUtils.optional(request, CommonParams.CLUSTER_NAME, StringUtils.EMPTY);\n        if (StringUtils.isBlank(cluster)) {\n            cluster = WebUtils.optional(request, \"cluster\", UtilsAndCommons.DEFAULT_CLUSTER_NAME);\n        }\n        actualBuilder.setClusterName(cluster);\n    }\n    \n    private void setEnabled(HttpServletRequest request) {\n        String enabledString = WebUtils.optional(request, \"enabled\", StringUtils.EMPTY);\n        boolean enabled;","sourceCodeStart":93,"sourceCodeEnd":129,"githubUrl":"https://github.com/alibaba/nacos/blob/9b989acdf181d00898f2e8839257bb2b2a3cefe3/naming/src/main/java/com/alibaba/nacos/naming/pojo/instance/HttpRequestInstanceBuilder.java#L93-L129","documentation":"Thrown by HttpRequestInstanceBuilder.setWeight() when an instance-registration HTTP request supplies a 'weight' outside [Constants.MIN_WEIGHT_VALUE, Constants.MAX_WEIGHT_VALUE] = [0.0, 10000.0]. Weight scales instance selection probability, so out-of-range values break load balancing; the builder returns NacosException.INVALID_PARAM. Note the range is inclusive bounds 0.0..10000.0.","triggerScenarios":"POST /v3/admin/ns/instance (or legacy /nacos/v1/ns/instance) with weight < 0 or > 10000, e.g. weight=50000 or weight=-1. The default weight is 1 when the param is omitted.","commonSituations":"Passing weight as a percentage (e.g. 100 meaning 100%); copy-paste error with an extra digit; weight=0 intended to drain traffic (valid - 0.0 is allowed, but negative values are not).","solutions":["Set weight to a value within 0.0 .. 10000.0 (default 1).","If you meant a percentage, map 0-100% onto the Nacos weight scale yourself.","Use weight=0 to take an instance out of rotation (allowed), never a negative number."],"exampleFix":"// before\ncurl -X POST '.../ns/instance' -d '...&weight=99999'\n// after\ncurl -X POST '.../ns/instance' -d '...&weight=100'","handlingStrategy":"validation","validationCode":"double w = (weight == null) ? 1.0d : weight;\nif (w < 0.0d || w > 10000.0d) {\n    throw new IllegalArgumentException(\"weight must be in [0.0, 10000.0]\");\n}\nrequest.addParameter(\"weight\", String.valueOf(w));","typeGuard":"static boolean isValidWeight(Double w) {\n    return w != null && w >= 0.0d && w <= 10000.0d;\n}","tryCatchPattern":"try {\n    namingService.registerInstance(serviceName, ip, port);\n} catch (NacosException e) {\n    if (e.getErrCode() == NacosException.INVALID_PARAM\n        && e.getMessage().contains(\"weights range\")) {\n        // correct the weight and retry once\n        instance.setWeight(Math.min(Math.max(instance.getWeight(), 0.0d), 10000.0d));\n    } else {\n        throw e;\n    }\n}","preventionTips":["Treat weight on Nacos' absolute scale, not a percentage.","Clamp user-supplied weight to [0,10000] before sending.","Remember 0 is valid (drain), negatives are not."],"tags":["naming","rest-api","validation","invalid-param","instance","weight"],"backgroundTag":null,"analyzedSha":"9b989acdf181d00898f2e8839257bb2b2a3cefe3","analyzedAt":"2026-08-14T07:17:31.569Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}