alibaba/nacos · error · IllegalArgumentException
Cannot convert String [{}] to Integer
Error message
Cannot convert String [{}] to Integer What it means
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.
Source
Thrown at client-basic/src/main/java/com/alibaba/nacos/client/env/convert/IntegerConverter.java:31
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.nacos.client.env.convert;
import com.alibaba.nacos.common.utils.StringUtils;
class IntegerConverter extends AbstractPropertyConverter<Integer> {
@Override
Integer convert(String property) {
if (StringUtils.isEmpty(property)) {
return null;
}
try {
return Integer.valueOf(property);
} catch (Exception e) {
throw new IllegalArgumentException(
"Cannot convert String [" + property + "] to Integer");
}
}
}
View on GitHub (pinned to 9b989acdf1)
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.
Example fix
// before
props.setProperty("some.int.property", "1,000");
// after
props.setProperty("some.int.property", "1000"); Defensive patterns
Strategy: validation
Validate before calling
String raw = properties.getProperty("some.int.property");
if (raw != null && !raw.isEmpty()) {
try {
Integer.parseInt(raw.trim());
} catch (NumberFormatException e) {
throw new IllegalArgumentException("Property must be a valid integer: " + raw, e);
}
} Try / catch
try {
Integer value = Integer.valueOf(raw);
} catch (NumberFormatException e) {
// Use a safe default or log a warning
value = defaultValue;
} Prevention
- Remove thousands separators and units from integer property values.
- Validate numeric properties at application startup.
- Use trim() to handle accidental whitespace in property values.
When it happens
Trigger: 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.
Common situations: Locale-specific number formatting with commas; hexadecimal or scientific notation; copy-paste errors; values with units appended (e.g. '100ms').
Related errors
- Invalid boolean value '{}'
- Cannot convert String [{property}] to Long
- [http-client] invalid connect timeout:{}
- Illegal url path expression
- converter not found, can't convert from String to {}
AI-assisted analysis of alibaba/nacos@9b989acdf1 (2026-08-14).
Data as JSON: /api/errors/5ead55ea9f12a891.
Report an issue: GitHub.