alibaba/nacos · error · IllegalArgumentException

invalid dataId

Error message

invalid dataId

What it means

Thrown as IllegalArgumentException by GroupKey.doGetKey() when the dataId parameter is null or blank (StringUtils.isBlank). doGetKey() is called by getKey(dataId, group), getKey(dataId, group, datumStr), and getKeyTenant(dataId, group, tenant). The group key is the internal composite key used by the Nacos config client to track configurations, so a blank dataId makes the key meaningless.

Source

Thrown at client/src/main/java/com/alibaba/nacos/client/config/common/GroupKey.java:52

    private static final char B = 'B';
    
    private static final char FIVE = '5';
    
    public static String getKey(String dataId, String group) {
        return getKey(dataId, group, "");
    }
    
    public static String getKey(String dataId, String group, String datumStr) {
        return doGetKey(dataId, group, datumStr);
    }
    
    public static String getKeyTenant(String dataId, String group, String tenant) {
        return doGetKey(dataId, group, tenant);
    }
    
    private static String doGetKey(String dataId, String group, String datumStr) {
        if (StringUtils.isBlank(dataId)) {
            throw new IllegalArgumentException("invalid dataId");
        }
        if (StringUtils.isBlank(group)) {
            throw new IllegalArgumentException("invalid group");
        }
        StringBuilder sb = new StringBuilder();
        urlEncode(dataId, sb);
        sb.append(PLUS);
        urlEncode(group, sb);
        if (StringUtils.isNotEmpty(datumStr)) {
            sb.append(PLUS);
            urlEncode(datumStr, sb);
        }
        
        return sb.toString();
    }
    
    /**
     * Parse key.

View on GitHub (pinned to 9b989acdf1)

Solutions

  1. Validate dataId is non-blank before calling GroupKey.getKey() or before registering listeners/querying configs.
  2. Trace upstream: find where the null/blank dataId originated — often a missing property or uninitialized field.
  3. If dataId comes from user input or external config, add a validation guard at the API boundary.

Example fix

// before
String key = GroupKey.getKey(dataId, group); // throws if dataId is null

// after: validate before composing key
if (StringUtils.isBlank(dataId)) {
    throw new IllegalArgumentException("dataId must not be blank");
}
String key = GroupKey.getKey(dataId, group);
Defensive patterns

Strategy: validation

Validate before calling

// Validate dataId before building a group key
if (StringUtils.isBlank(dataId)) {
    throw new IllegalArgumentException("dataId must not be null or blank");
}
String key = GroupKey.getKey(dataId, group);

Try / catch

try {
    String key = GroupKey.getKey(dataId, group);
} catch (IllegalArgumentException e) {
    if (e.getMessage().contains("invalid dataId")) {
        log.error("dataId is blank — check the caller passed a valid config dataId");
    }
    throw e;
}

Prevention

When it happens

Trigger: Any call to GroupKey.getKey() or GroupKey.getKeyTenant() with a null, empty, or whitespace-only dataId. This typically happens in config listener registration, cache management, or config query paths where dataId was not validated upstream.

Common situations: Config listener registered with a null dataId (e.g., ConfigService.addListener(null, group, listener)). Config query via ConfigService.getConfig(null, group, timeout). Deserialization or callback code that passes an unvalidated dataId from user input or a malformed config reference.

Related errors


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