apolloconfig/apollo · warning · BadRequestException

line:{} key value must separate by '='

Error message

line:{} key value must separate by '='

What it means

BadRequestException (HTTP 400) from isHasRepeatKey. While scanning lines for duplicate keys, parseKeyValueFromItem returns null when a non-comment, non-blank line contains no '=' character, and the resolver immediately rejects it, naming the 1-based line number. This guard runs before the change-set is built.

Source

Thrown at apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/component/txtresolver/PropertyResolver.java:132

    deleteCommentAndBlankItem(baseCommentItems, baseBlankItems, changeSets);
    deleteNormalKVItem(oldKeyMapItem, changeSets);

    return changeSets;
  }

  private boolean isHasRepeatKey(String[] newItems, @NotNull Set<String> repeatKeys) {
    Set<String> keys = new HashSet<>();
    int lineCounter = 1;
    for (String item : newItems) {
      if (!isCommentItem(item) && !isBlankItem(item)) {
        String[] kv = parseKeyValueFromItem(item);
        if (kv != null) {
          String key = kv[0].toLowerCase();
          if (!keys.add(key)) {
            repeatKeys.add(key);
          }
        } else {
          throw new BadRequestException("line:" + lineCounter + " key value must separate by '='");
        }
      }
      lineCounter++;
    }
    return !repeatKeys.isEmpty();
  }

  private String[] parseKeyValueFromItem(String item) {
    int kvSeparator = item.indexOf(KV_SEPARATOR);
    if (kvSeparator == -1) {
      return null;
    }

    String[] kv = new String[2];
    kv[0] = item.substring(0, kvSeparator).trim();
    kv[1] = item.substring(kvSeparator + 1).trim();
    return kv;
  }

View on GitHub (pinned to d95fc18d11)

Solutions

  1. Edit line N (the number in the message) so it is 'key=value'.
  2. If the line is documentation, prefix it with '#' so it is treated as a comment.
  3. If the line is empty, leave it truly empty (whitespace only) so isBlankItem matches.
  4. Replace ':' separators with '='; Apollo properties do not accept the key:value form here.

Example fix

// before (line 3 has no '=')
app.name=demo
app.env=prod
this is a note

// after
app.name=demo
app.env=prod
# this is a note
Defensive patterns

Strategy: validation

Validate before calling

// Surface every line missing '=' BEFORE submit (1-based line numbers, comments/blanks ignored).
List<Integer> linesMissingEquals(String configText) {
  List<Integer> bad = new ArrayList<>();
  String[] lines = configText.split("\\r?\\n", -1);
  for (int i = 0; i < lines.length; i++) {
    String line = lines[i].trim();
    if (line.isEmpty() || line.startsWith("#")) continue;
    if (line.indexOf('=') < 0) bad.add(i + 1);
  }
  return bad;
}
// assert linesMissingEquals(text).isEmpty()

Prevention

When it happens

Trigger: Saving namespace config text where a line is neither a comment (#), nor blank, nor a valid 'key=value' pair (e.g. a bare word, a line using ':' as separator, or a value with no key).

Common situations: Pasting YAML/INI style 'key: value' into a properties namespace; a stray word or footnote without '='; a line whose only '=' is inside a comment that was not prefixed with #.

Related errors


AI-assisted analysis of apolloconfig/apollo@d95fc18d11 (2026-08-14). Data as JSON: /api/errors/60695bdcf8768ab7. Report an issue: GitHub.