alibaba/nacos · error · IllegalArgumentException

Plugin config value cannot be null: {key}

Error message

Plugin config value cannot be null: {key}

What it means

Thrown by LdapAuthPluginConfig.value() when the effective configuration map explicitly contains a key but its value is null. This is distinct from a missing key (which returns the default). The presence of key->null in the map signals a malformed configuration source, so the parser rejects it with IllegalArgumentException naming the offending key.

Source

Thrown at plugin-default-impl/nacos-ldap-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/ldap/LdapAuthPluginConfig.java:132

        String password = value(config, PASSWORD, DEFAULT_PASSWORD);
        String filterPrefix = value(config, FILTER_PREFIX, DEFAULT_FILTER_PREFIX);
        boolean caseSensitive = parseBoolean(value(config, CASE_SENSITIVE,
            Boolean.toString(DEFAULT_CASE_SENSITIVE)), CASE_SENSITIVE);
        boolean ignorePartialResultException = parseBoolean(value(config,
            IGNORE_PARTIAL_RESULT_EXCEPTION,
            Boolean.toString(DEFAULT_IGNORE_PARTIAL_RESULT_EXCEPTION)),
            IGNORE_PARTIAL_RESULT_EXCEPTION);
        return new LdapAuthPluginConfig(url, baseDn, timeout, userDn, password, filterPrefix,
            caseSensitive, ignorePartialResultException);
    }
    
    private static String value(Map<String, String> config, String key, String defaultValue) {
        if (config == null || !config.containsKey(key)) {
            return defaultValue;
        }
        String result = config.get(key);
        if (result == null) {
            throw new IllegalArgumentException("Plugin config value cannot be null: " + key);
        }
        return result;
    }
    
    private static long parsePositiveLong(String value, String key) {
        try {
            long result = Long.parseLong(value);
            if (result <= 0) {
                throw new IllegalArgumentException("Plugin config value must be positive: " + key);
            }
            return result;
        } catch (NumberFormatException e) {
            throw new IllegalArgumentException("Plugin config value is not a number: " + key, e);
        }
    }
    
    private static boolean parseBoolean(String value, String key) {
        if (!Boolean.TRUE.toString().equalsIgnoreCase(value)

View on GitHub (pinned to 9b989acdf1)

Solutions

  1. Inspect the error message to identify which key has the null value, then provide an explicit value in the config source.
  2. If the key should be optional, remove it from the config map entirely so the default kicks in (the from() method only throws when the key is present-but-null).
  3. Sanitize the config map before passing it to from(): strip entries whose value is null.

Example fix

// before: map contains a key with null value
Map<String,String> config = new HashMap<>();
config.put("url", null); // present but null -> throws
LdapAuthPluginConfig.from(config);

// after: omit the key so the default applies, or set a real value
Map<String,String> config = new HashMap<>();
// url omitted -> defaults to ldap://localhost:389
LdapAuthPluginConfig.from(config);
Defensive patterns

Strategy: validation

Validate before calling

// Strip null-valued entries before parsing
Map<String, String> sanitized = new LinkedHashMap<>();
for (Map.Entry<String, String> entry : config.entrySet()) {
    if (entry.getValue() != null) {
        sanitized.put(entry.getKey(), entry.getValue());
    }
}
LdapAuthPluginConfig.from(sanitized);

Type guard

static boolean hasNoNullValues(Map<String, String> config) {
    return config == null || config.values().stream().noneMatch(Objects::isNull);
}

Try / catch

try {
    LdapAuthPluginConfig parsed = LdapAuthPluginConfig.from(config);
} catch (IllegalArgumentException e) {
    // message names the offending key; fix the config source
}

Prevention

When it happens

Trigger: LdapAuthPluginConfig.from(config) is called with a Map where one of the known keys (url, base-dn, timeout, user-dn, password, filter-prefix, case-sensitive, ignore-partial-result-exception) is present but maps to a null value.

Common situations: A YAML/properties file declares a key with no value (e.g. "nacos.plugin.auth.ldap.url="); a config-loading layer puts the key in the map with a null placeholder; an environment variable override resolves to null.

Related errors


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