alibaba/nacos · error · IllegalArgumentException

Invalid boolean value '{}'

Error message

Invalid boolean value '{}'

What it means

Thrown by BooleanConverter.convert() as an IllegalArgumentException when the property string (case-insensitively) is not one of the accepted boolean values. Accepted TRUE values: 'true', 'on', 'yes', '1'. Accepted FALSE values: 'false', 'off', 'no', '0'. An empty or null string returns null (no error). Any other value throws. This converter is used by NacosClientProperties to coerce string-based configuration values to Boolean.

Source

Thrown at client-basic/src/main/java/com/alibaba/nacos/client/env/convert/BooleanConverter.java:53

        
        FALSE_VALUES.add("false");
        FALSE_VALUES.add("off");
        FALSE_VALUES.add("no");
        FALSE_VALUES.add("0");
    }
    
    @Override
    Boolean convert(String property) {
        if (StringUtils.isEmpty(property)) {
            return null;
        }
        property = property.toLowerCase();
        if (TRUE_VALUES.contains(property)) {
            return Boolean.TRUE;
        } else if (FALSE_VALUES.contains(property)) {
            return Boolean.FALSE;
        } else {
            throw new IllegalArgumentException("Invalid boolean value '" + property + "'");
        }
    }
}

View on GitHub (pinned to 9b989acdf1)

Solutions

  1. Check the property value from the exception message and change it to one of: true, false, on, off, yes, no, 1, 0.
  2. If the value comes from an external system, normalize it to a recognized boolean string before injecting it into NacosClientProperties.

Example fix

// before
props.setProperty("some.boolean.flag", "enabled");

// after
props.setProperty("some.boolean.flag", "true");
Defensive patterns

Strategy: validation

Validate before calling

Set<String> valid = Set.of("true", "false", "on", "off", "yes", "no", "1", "0");
String val = properties.getProperty("some.boolean.flag");
if (val != null && !valid.contains(val.toLowerCase())) {
    throw new IllegalArgumentException("Boolean property must be one of " + valid + ", got: " + val);
}

Try / catch

try {
    Boolean value = nacosClientProperties.getProperty("flag", Boolean.class);
} catch (IllegalArgumentException e) {
    if (e.getMessage().contains("Invalid boolean value")) {
        // Default to false or prompt for correction
        properties.setProperty("flag", "false");
    } else {
        throw e;
    }
}

Prevention

When it happens

Trigger: A Nacos property expected to be boolean contains a value like 'Y', 'enable', 'disabled', '2', or any string not in the accepted set. The check is case-insensitive (toLowerCase is applied), so 'TRUE' works but 'Yeah' does not.

Common situations: Operators set a boolean property to 'enabled' or 'disabled' instead of 'true'/'false'; YAML 1.1 boolean parsing produces 'yes'/'no' which IS accepted but 'on'/'off' in unexpected contexts; numeric values other than 0/1.

Related errors


AI-assisted analysis of alibaba/nacos@9b989acdf1 (2026-08-14). Data as JSON: /api/errors/5c172df06b5d031d. Report an issue: GitHub.