{"record":{"id":"dda57a79d93bf71b","repo":"stanfordnlp/CoreNLP","slug":"unclosed-bracket-in-encoded-map-encoded","errorCode":null,"errorMessage":"Unclosed bracket in encoded map: \" + encoded","messagePattern":"Unclosed bracket in encoded map: \" \\+ encoded","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/util/StringUtils.java","lineNumber":2631,"sourceCode":"   * @param encoded The String encoded map\n   * @return A String map corresponding to the encoded map\n   */\n  public static Map<String, String> decodeMap(String encoded){\n    if (encoded.isEmpty()) return new HashMap<>();\n    char[] chars = encoded.trim().toCharArray();\n\n    //--Parse the String\n    //(state)\n    char quoteCloseChar = (char) 0;\n    Map<String, String> map = new HashMap<>();\n    String key = \"\";\n    String value = \"\";\n    boolean onKey = true;\n    StringBuilder current = new StringBuilder();\n    //(start/stop overhead)\n    int start = 0; int end = chars.length;\n    if(chars[0] == '('){ start += 1; end -= 1; if(chars[end] != ')') throw new IllegalArgumentException(\"Unclosed paren in encoded map: \" + encoded); }\n    if(chars[0] == '['){ start += 1; end -= 1; if(chars[end] != ']') throw new IllegalArgumentException(\"Unclosed bracket in encoded map: \" + encoded); }\n    if(chars[0] == '{'){ start += 1; end -= 1; if(chars[end] != '}') throw new IllegalArgumentException(\"Unclosed bracket in encoded map: \" + encoded); }\n    //(finite state automata)\n    for(int i=start; i<end; i++){\n      if (chars[i] == '\\r') {\n        // Ignore funny windows carriage return\n        continue;\n      } else if(quoteCloseChar != 0){\n        //(case: in quotes)\n        if(chars[i] == quoteCloseChar){\n          quoteCloseChar = (char) 0;\n        }else{\n          current.append(chars[i]);\n        }\n      } 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        }","sourceCodeStart":2613,"sourceCodeEnd":2649,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/util/StringUtils.java#L2613-L2649","documentation":"A malformed-input error in StringUtils.decodeMap: the encoded map string must wrap its entries in matching brackets; the parser reached the end (or hit inconsistency) without finding the expected closing bracket, so the encoding is corrupt or truncated.","triggerScenarios":"Passing a map string starting with '[' whose last character is not ']' (e.g. \"[a->1\", \"[a->1)\").","commonSituations":"Bracket/paren mix-ups when writing encoded maps by hand; code that changed delimiters but not both ends; truncated strings from logs or config edits.","solutions":["Add the missing ']' as the last character","Fix the string builder to pair the opening '[' with a closing ']'","Validate delimiter balance before decoding","Handle IllegalArgumentException where untrusted strings are decoded"],"exampleFix":"// before\nStringUtils.decodeMap(\"[a->1\");\n// after\nStringUtils.decodeMap(\"[a->1]\");","handlingStrategy":"validation","validationCode":"if (s != null && s.startsWith(\"[\") && !s.endsWith(\"]\")) throw new IllegalArgumentException(\"Encoded map must end with ']': \" + s);","typeGuard":"static boolean isBracketClosed(String s) { return s != null && s.length() >= 2 && s.charAt(0)=='[' && s.charAt(s.length()-1)==']'; }","tryCatchPattern":null,"preventionTips":["Do not mix paren and bracket delimiters when editing configs","Generate encoded maps with a single tested serializer","Validate delimiter balance before decode calls"],"tags":["java","string-parsing","malformed-input","map-parsing"],"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"}