{"record":{"id":"c5f4937b4a3dda3d","repo":"alibaba/nacos","slug":"processors-scale-must-between-0-and-1","errorCode":null,"errorMessage":"processors scale must between 0 and 1","messagePattern":"processors scale must between 0 and 1","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"sys/src/main/java/com/alibaba/nacos/sys/env/EnvUtil.java","lineNumber":509,"sourceCode":"     */\n    public static int getAvailableProcessors(int multiple) {\n        if (multiple < 1) {\n            throw new IllegalArgumentException(\"processors multiple must upper than 1\");\n        }\n        Integer processor = getProperty(Constants.AVAILABLE_PROCESSORS_BASIC, Integer.class);\n        return null != processor && processor > 0 ? processor * multiple\n            : ThreadUtils.getSuitableThreadCount(multiple);\n    }\n    \n    /**\n     * Get a scale of available processor numbers from environment.\n     *\n     * @param scale scale from 0 to 1.\n     * @return available processor numbers from environment, will not lower than 1.\n     */\n    public static int getAvailableProcessors(double scale) {\n        if (scale < 0 || scale > 1) {\n            throw new IllegalArgumentException(\"processors scale must between 0 and 1\");\n        }\n        double result =\n            getProperty(Constants.AVAILABLE_PROCESSORS_BASIC, int.class,\n                ThreadUtils.getSuitableThreadCount(1))\n                * scale;\n        return result > 1 ? (int) result : 1;\n    }\n    \n    public static DeploymentType getDeploymentType() {\n        return deploymentType;\n    }\n    \n    public static void setDeploymentType(DeploymentType deploymentType) {\n        EnvUtil.deploymentType = deploymentType;\n    }\n}\n","sourceCodeStart":491,"sourceCodeEnd":526,"githubUrl":"https://github.com/alibaba/nacos/blob/9b989acdf181d00898f2e8839257bb2b2a3cefe3/sys/src/main/java/com/alibaba/nacos/sys/env/EnvUtil.java#L491-L526","documentation":"Thrown by EnvUtil.getAvailableProcessors(double scale) when the scale is outside [0, 1]. The method sizes pools as a fraction of available processors and rejects out-of-range fractions.","triggerScenarios":"A caller passes a scale < 0 or > 1, usually from a misconfigured ratio property (e.g. 1.5 meaning '150%' or a negative value).","commonSituations":"A thread-pool ratio property set to >1 (user thinking percentage) or negative; a derived ratio computed incorrectly; configuration imported from another system with a different scale convention.","solutions":["Find the caller of getAvailableProcessors(double) and ensure scale is within [0, 1].","If the property is a percentage, divide by 100 before passing (e.g. 75 -> 0.75).","Clamp the value: Math.max(0.0, Math.min(1.0, scale)).","Correct the source configuration value."],"exampleFix":"// before\n// config: nacos.thread.pool.ratio=150 (intended as 150%)\ndouble scale = 150.0;\nint size = EnvUtil.getAvailableProcessors(scale); // throws\n\n// after\ndouble scale = 150.0 / 100.0; // 1.0, or clamp\nint size = EnvUtil.getAvailableProcessors(Math.min(1.0, scale));","handlingStrategy":"validation","validationCode":"double scale = configuredScale; // from config\nif (scale < 0 || scale > 1) {\n    throw new IllegalArgumentException(\"thread scale must be in [0,1], got \" + scale);\n}\nint size = EnvUtil.getAvailableProcessors(scale);","typeGuard":null,"tryCatchPattern":"try {\n    EnvUtil.getAvailableProcessors(scale);\n} catch (IllegalArgumentException e) {\n    // treat as percentage or clamp\n    EnvUtil.getAvailableProcessors(Math.max(0.0, Math.min(1.0, scale)));\n}","preventionTips":["Document ratio properties as fractions in [0,1], not percentages.","Clamp derived scales before calling.","Validate at startup and fail fast with a clear message."],"tags":["sys","configuration","thread-pool","startup"],"backgroundTag":null,"analyzedSha":"9b989acdf181d00898f2e8839257bb2b2a3cefe3","analyzedAt":"2026-08-14T07:17:31.569Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}