{"record":{"id":"96d051c139169ede","repo":"stanfordnlp/CoreNLP","slug":"unclosed-paren-in-encoded-map-encoded","errorCode":null,"errorMessage":"Unclosed paren in encoded map: \" + encoded","messagePattern":"Unclosed paren in encoded map: \" \\+ encoded","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/util/StringUtils.java","lineNumber":2630,"sourceCode":"   *\n   * @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);","sourceCodeStart":2612,"sourceCodeEnd":2648,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/util/StringUtils.java#L2612-L2648","documentation":"StringUtils' encoded-map decoder accepts maps wrapped in parentheses, brackets, or braces. If the string starts with '(' the decoder strips one character from each end and requires the final character to be ')'. A mismatch means the encoded map is unbalanced and the decoder throws IllegalArgumentException.","triggerScenarios":"Calling the public StringUtils map-decode method with a string starting with '(' whose last character is not ')' (e.g. \"(key->value\", \"(k:v]\").","commonSituations":"Hand-written map strings in config/properties-style files with a missing closer; programmatic builders emitting mismatched delimiters; truncation by copy-paste or log capture.","solutions":["Append the closing ')' to the encoded map string","Fix the generator to emit matching open/close delimiters","Trim trailing whitespace or stray characters before decoding","Catch IllegalArgumentException and validate user-supplied map strings"],"exampleFix":"// before\nStringUtils.decodeMap(\"(a->1, b->2\");\n// after\nStringUtils.decodeMap(\"(a->1, b->2)\");","handlingStrategy":"validation","validationCode":"if (s != null && s.startsWith(\"(\") && !s.endsWith(\")\")) throw new IllegalArgumentException(\"Encoded map must end with ')': \" + s);","typeGuard":"static boolean isParenClosed(String s) { return s != null && s.length() >= 2 && s.charAt(0)=='(' && s.charAt(s.length()-1)==')'; }","tryCatchPattern":"try { map = StringUtils.decodeMap(encoded); } catch (IllegalArgumentException e) { log.error(\"Malformed encoded map: \" + encoded, e); throw e; }","preventionTips":["Pair every opening delimiter with its closer in emitters","Trim whitespace/stray chars before decoding","Validate user-supplied map strings before decoding"],"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"}