stanfordnlp/CoreNLP · error · IllegalArgumentException

Encountered a value without a key

Error message

Encountered a value without a key

What it means

In the encoded-map automaton, the '->' token ends a key. If '->' is encountered while a value is being parsed (onKey == false), the string contains a second key/value delimiter inside a value, meaning a value was never properly terminated — the decoder throws IllegalArgumentException.

Solutions

  1. Escape or quote the '->' inside the value if supported, or remove it
  2. Use a different separator syntax (e.g. 'k:v') for values containing '->'
  3. Sanitize values to strip or replace '->' before encoding
  4. Catch IllegalArgumentException and pinpoint the offending segment

Example fix

// before
StringUtils.decodeMap("(a->b->c)");
// after
StringUtils.decodeMap("(a->b arrow c)");
Defensive patterns

Strategy: validation

Validate before calling

for (String entry : body.split(",")) { int idx = entry.indexOf("->"); if (idx != entry.lastIndexOf("->")) throw new IllegalArgumentException("Value contains '->': " + entry); }

Try / catch

try { map = StringUtils.decodeMap(encoded); } catch (IllegalArgumentException e) { if (e.getMessage().contains("value without a key")) { /* sanitize '->' in values */ } throw e; }

Prevention

When it happens

Trigger: Passing a map string like "(a->b->c)" where a value contains an unescaped '->'; or a value containing '=>' at the wrong state.

Common situations: Values that legitimately contain '->' (arrows in text, lambda descriptions) without quoting/escaping; concatenated map strings; copy-paste merging two entries.

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/73e90bd212061b7b. Report an issue: GitHub.

Appendix: source

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

        } 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
        } else if (chars[i] == ':') {
          // 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;
        } else {

View on GitHub (pinned to 1b7edd19c4)