stanfordnlp/CoreNLP · error · IllegalArgumentException

Encountered key without value

Error message

Encountered key without value

What it means

In the encoded-map automaton, a separator (',', ';', tab, or newline) ends a value. If the separator is hit while still parsing a key (onKey == true), the map contains a key with no '->' or ':' before the separator, i.e. a dangling key, so the decoder throws IllegalArgumentException.

Solutions

  1. Add the missing '->' or ':' between the key and its value
  2. Remove the orphan key or give it a value
  3. Check multi-line strings: every key must be followed by a delimiter and value before any separator
  4. Catch IllegalArgumentException and validate the map syntax before decoding

Example fix

// before
StringUtils.decodeMap("(a, b->2)");
// after
StringUtils.decodeMap("(a->1, b->2)");
Defensive patterns

Strategy: validation

Validate before calling

for (String entry : body.split("[,;\\t\\n]")) if (!entry.contains("->") && !entry.contains(":")) throw new IllegalArgumentException("Entry missing key/value delimiter: " + entry);

Try / catch

try { map = StringUtils.decodeMap(encoded); } catch (IllegalArgumentException e) { if (e.getMessage().equals("Encountered key without value")) { /* locate segment without '->' or ':' */ } throw e; }

Prevention

When it happens

Trigger: Passing a map string like "(a, b->2)" or "(a; b->2)" where a separator follows a key without a key/value delimiter; also an empty segment like "(->v, a->1)" depending on state.

Common situations: Hand-written maps forgetting the '->' or ':' between key and value; multi-line encoded maps where a line holds only a key; edited config strings with a deleted value.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10). Data as JSON: /api/errors/2c08017c2dc8e76d. Report an issue: GitHub.

Appendix: source

Thrown at src/edu/stanford/nlp/util/StringUtils.java:2663

      } else if(chars[i] == '\\'){
        //(case: escaped character)
        if(i == chars.length - 1) {
          throw new IllegalArgumentException("Last character of encoded pair is escape character: " + encoded);
        }
        current.append(chars[i+1]);
        i += 1;
      }else{
        //(case: normal)
        if (chars[i] == '"') {
          quoteCloseChar = '"';
        } else if(chars[i] == '\'') {
          quoteCloseChar = '\'';
        } else if (chars[i] == '\n' && current.length() == 0) {
          // current.append("");  // do nothing
        } else if(chars[i] == ',' || chars[i] == ';' || chars[i] == '\t' || chars[i] == '\n'){
          // case: end a value
          if (onKey) {
            throw new IllegalArgumentException("Encountered key without value");
          }
          if (current.length() > 0) {
            value = current.toString().trim();
          }
          current = new StringBuilder();
          onKey = true;
          map.put(key, value);  // <- add value
        } else if((chars[i] == '-' || chars[i] == '=') && (i < chars.length - 1 && chars[i + 1] == '>')) {
          // case: end a key
          if (!onKey) {
            throw new IllegalArgumentException("Encountered a value without a key");
          }
          if (current.length() > 0) {
            key = current.toString().trim();
          }
          current = new StringBuilder();
          onKey = false;
          i += 1; // skip '>' character

View on GitHub (pinned to 1b7edd19c4)