{"record":{"id":"2c08017c2dc8e76d","repo":"stanfordnlp/CoreNLP","slug":"encountered-key-without-value","errorCode":null,"errorMessage":"Encountered key without value","messagePattern":"Encountered key without value","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/util/StringUtils.java","lineNumber":2663,"sourceCode":"      } else if(chars[i] == '\\\\'){\n        //(case: escaped character)\n        if(i == chars.length - 1) {\n          throw new IllegalArgumentException(\"Last character of encoded pair is escape character: \" + encoded);\n        }\n        current.append(chars[i+1]);\n        i += 1;\n      }else{\n        //(case: normal)\n        if (chars[i] == '\"') {\n          quoteCloseChar = '\"';\n        } else if(chars[i] == '\\'') {\n          quoteCloseChar = '\\'';\n        } else if (chars[i] == '\\n' && current.length() == 0) {\n          // current.append(\"\");  // do nothing\n        } else if(chars[i] == ',' || chars[i] == ';' || chars[i] == '\\t' || chars[i] == '\\n'){\n          // case: end a value\n          if (onKey) {\n            throw new IllegalArgumentException(\"Encountered key without value\");\n          }\n          if (current.length() > 0) {\n            value = current.toString().trim();\n          }\n          current = new StringBuilder();\n          onKey = true;\n          map.put(key, value);  // <- add value\n        } else if((chars[i] == '-' || chars[i] == '=') && (i < chars.length - 1 && chars[i + 1] == '>')) {\n          // case: end a key\n          if (!onKey) {\n            throw new IllegalArgumentException(\"Encountered a value without a key\");\n          }\n          if (current.length() > 0) {\n            key = current.toString().trim();\n          }\n          current = new StringBuilder();\n          onKey = false;\n          i += 1; // skip '>' character","sourceCodeStart":2645,"sourceCodeEnd":2681,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/util/StringUtils.java#L2645-L2681","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Add the missing '->' or ':' between the key and its value","Remove the orphan key or give it a value","Check multi-line strings: every key must be followed by a delimiter and value before any separator","Catch IllegalArgumentException and validate the map syntax before decoding"],"exampleFix":"// before\nStringUtils.decodeMap(\"(a, b->2)\");\n// after\nStringUtils.decodeMap(\"(a->1, b->2)\");","handlingStrategy":"validation","validationCode":"for (String entry : body.split(\"[,;\\\\t\\\\n]\")) if (!entry.contains(\"->\") && !entry.contains(\":\")) throw new IllegalArgumentException(\"Entry missing key/value delimiter: \" + entry);","typeGuard":null,"tryCatchPattern":"try { map = StringUtils.decodeMap(encoded); } catch (IllegalArgumentException e) { if (e.getMessage().equals(\"Encountered key without value\")) { /* locate segment without '->' or ':' */ } throw e; }","preventionTips":["Every key must be followed by '->' or ':' then a value","Check multi-line maps: no line should end with a bare key","Validate entry structure before decoding"],"tags":["java","map-parsing","malformed-input","syntax-error"],"backgroundTag":"invalid-argument-format","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}