{"record":{"id":"bbd580a19ba18d87","repo":"alibaba/nacos","slug":"cannot-convert-string-property-to-long","errorCode":null,"errorMessage":"Cannot convert String [{property}] to Long","messagePattern":"Cannot convert String \\[(.+?)\\] to Long","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"client-basic/src/main/java/com/alibaba/nacos/client/env/convert/LongConverter.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 LongConverter extends AbstractPropertyConverter<Long> {\n    \n    @Override\n    Long convert(String property) {\n        if (StringUtils.isEmpty(property)) {\n            return null;\n        }\n        try {\n            return Long.valueOf(property);\n        } catch (Exception e) {\n            throw new IllegalArgumentException(\"Cannot convert String [\" + property + \"] to Long\");\n        }\n    }\n}\n","sourceCodeStart":13,"sourceCodeEnd":35,"githubUrl":"https://github.com/alibaba/nacos/blob/9b989acdf181d00898f2e8839257bb2b2a3cefe3/client-basic/src/main/java/com/alibaba/nacos/client/env/convert/LongConverter.java#L13-L35","documentation":"Thrown by LongConverter.convert() as an IllegalArgumentException when Long.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 Long. The message includes the offending value in brackets.","triggerScenarios":"A Nacos property expected to be a long integer contains a non-numeric string (e.g. 'abc', '1.5', '1,000,000', '99999999999999999999' overflow).","commonSituations":"Large numeric IDs or timestamps formatted with separators; scientific notation; overflow beyond Long.MAX_VALUE; locale-specific comma separators.","solutions":["Check the property value in the exception message and ensure it is a valid 64-bit signed integer.","Remove thousands separators, units, and whitespace.","If the value represents a timestamp or duration, convert it to epoch millis or seconds before setting the property."],"exampleFix":"// before\nprops.setProperty(\"some.long.property\", \"1,700,000,000,000\");\n\n// after\nprops.setProperty(\"some.long.property\", \"1700000000000\");","handlingStrategy":"validation","validationCode":"String raw = properties.getProperty(\"some.long.property\");\nif (raw != null && !raw.isEmpty()) {\n    try {\n        Long.parseLong(raw.trim());\n    } catch (NumberFormatException e) {\n        throw new IllegalArgumentException(\"Property must be a valid long: \" + raw, e);\n    }\n}","typeGuard":null,"tryCatchPattern":"try {\n    Long value = Long.valueOf(raw);\n} catch (NumberFormatException e) {\n    value = defaultValue;\n}","preventionTips":["Remove thousands separators from long property values.","Validate that timestamps and IDs fit within Long range before setting properties.","Use trim() to eliminate whitespace in property values."],"tags":["configuration","type-conversion","validation","long"],"backgroundTag":null,"analyzedSha":"9b989acdf181d00898f2e8839257bb2b2a3cefe3","analyzedAt":"2026-08-14T07:17:31.569Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}