{"record":{"id":"3ec70833fced8362","repo":"alibaba/nacos","slug":"processors-multiple-must-upper-than-1","errorCode":null,"errorMessage":"processors multiple must upper than 1","messagePattern":"processors multiple must upper than 1","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"sys/src/main/java/com/alibaba/nacos/sys/env/EnvUtil.java","lineNumber":494,"sourceCode":"     * </p>\n     *\n     * @return available processor numbers from environment, will not lower than 1.\n     */\n    public static int getAvailableProcessors() {\n        int result = getProperty(Constants.AVAILABLE_PROCESSORS_BASIC, int.class,\n            ThreadUtils.getSuitableThreadCount(1));\n        return result > 0 ? result : 1;\n    }\n    \n    /**\n     * Get a multiple time of available processor numbers from environment.\n     *\n     * @param multiple multiple of available processor numbers\n     * @return available processor numbers from environment, will not lower than 1.\n     */\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,","sourceCodeStart":476,"sourceCodeEnd":512,"githubUrl":"https://github.com/alibaba/nacos/blob/9b989acdf181d00898f2e8839257bb2b2a3cefe3/sys/src/main/java/com/alibaba/nacos/sys/env/EnvUtil.java#L476-L512","documentation":"Thrown by EnvUtil.getAvailableProcessors(int multiple) when the supplied multiple is less than 1. The method sizes thread pools as a multiple of the available processor count and rejects non-positive multipliers.","triggerScenarios":"A caller passes a multiple < 1, typically derived from a misparsed configuration property (negative or zero thread multiplier).","commonSituations":"A thread-pool sizing property is set to 0 or negative in custom config; a plugin computes a multiplier from a ratio that underflows to <= 0; refactoring introduces an off-by-one producing 0.","solutions":["Find the caller of getAvailableProcessors(int) and ensure the multiplier is >= 1.","If the value comes from config, validate/clamp it to a minimum of 1 before calling.","Search the codebase for the property feeding the multiplier and correct its value.","Add a unit test asserting the multiplier stays positive for expected config ranges."],"exampleFix":"// before\nint poolSize = EnvUtil.getAvailableProcessors(configuredMultiple); // configuredMultiple = 0\n\n// after\nint multiple = Math.max(1, configuredMultiple);\nint poolSize = EnvUtil.getAvailableProcessors(multiple);","handlingStrategy":"validation","validationCode":"int multiple = configuredMultiple; // from config\nif (multiple < 1) {\n    throw new IllegalArgumentException(\"thread multiplier must be >= 1, got \" + multiple);\n}\nint size = EnvUtil.getAvailableProcessors(multiple);","typeGuard":null,"tryCatchPattern":"try {\n    EnvUtil.getAvailableProcessors(multiple);\n} catch (IllegalArgumentException e) {\n    // clamp and retry, or fail startup with config context\n    EnvUtil.getAvailableProcessors(Math.max(1, multiple));\n}","preventionTips":["Clamp configuration-derived multipliers to >= 1 before calling.","Validate thread-pool sizing properties at startup.","Add tests covering boundary (0, 1, negative) inputs."],"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"}