{"record":{"id":"5ead55ea9f12a891","repo":"alibaba/nacos","slug":"cannot-convert-string-to-integer","errorCode":null,"errorMessage":"Cannot convert String [{}] to Integer","messagePattern":"Cannot convert String \\[(.+?)\\] to Integer","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"client-basic/src/main/java/com/alibaba/nacos/client/env/convert/IntegerConverter.java","lineNumber":31,"sourceCode":" * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\npackage com.alibaba.nacos.client.env.convert;\n\nimport com.alibaba.nacos.common.utils.StringUtils;\n\nclass IntegerConverter extends AbstractPropertyConverter<Integer> {\n    \n    @Override\n    Integer convert(String property) {\n        if (StringUtils.isEmpty(property)) {\n            return null;\n        }\n        try {\n            return Integer.valueOf(property);\n        } catch (Exception e) {\n            throw new IllegalArgumentException(\n                \"Cannot convert String [\" + property + \"] to Integer\");\n        }\n    }\n}\n","sourceCodeStart":13,"sourceCodeEnd":36,"githubUrl":"https://github.com/alibaba/nacos/blob/9b989acdf181d00898f2e8839257bb2b2a3cefe3/client-basic/src/main/java/com/alibaba/nacos/client/env/convert/IntegerConverter.java#L13-L36","documentation":"Thrown by IntegerConverter.convert() as an IllegalArgumentException when Integer.valueOf(property) fails. An empty or null string returns null (no error). This converter is used internally by NacosClientProperties to coerce string property values to Integer. The message includes the offending value.","triggerScenarios":"A Nacos property expected to be an integer contains a non-numeric string (e.g. 'abc', '1.5', '3,000', '0x1F'). Overflow values exceeding Integer.MAX_VALUE also trigger NumberFormatException internally.","commonSituations":"Locale-specific number formatting with commas; hexadecimal or scientific notation; copy-paste errors; values with units appended (e.g. '100ms').","solutions":["Check the property value in the exception message and ensure it is a valid 32-bit signed integer.","Remove thousands separators, units, and whitespace from the value.","If the value exceeds Integer range, consider whether a Long property is more appropriate."],"exampleFix":"// before\nprops.setProperty(\"some.int.property\", \"1,000\");\n\n// after\nprops.setProperty(\"some.int.property\", \"1000\");","handlingStrategy":"validation","validationCode":"String raw = properties.getProperty(\"some.int.property\");\nif (raw != null && !raw.isEmpty()) {\n    try {\n        Integer.parseInt(raw.trim());\n    } catch (NumberFormatException e) {\n        throw new IllegalArgumentException(\"Property must be a valid integer: \" + raw, e);\n    }\n}","typeGuard":null,"tryCatchPattern":"try {\n    Integer value = Integer.valueOf(raw);\n} catch (NumberFormatException e) {\n    // Use a safe default or log a warning\n    value = defaultValue;\n}","preventionTips":["Remove thousands separators and units from integer property values.","Validate numeric properties at application startup.","Use trim() to handle accidental whitespace in property values."],"tags":["configuration","type-conversion","validation","integer"],"backgroundTag":null,"analyzedSha":"9b989acdf181d00898f2e8839257bb2b2a3cefe3","analyzedAt":"2026-08-14T07:17:31.569Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}