{"record":{"id":"15da41a3b70cf62f","repo":"stanfordnlp/CoreNLP","slug":"unclosed-bracke-in-encoded-array-encoded","errorCode":null,"errorMessage":"Unclosed bracke in encoded array: \" + encoded","messagePattern":"Unclosed bracke in encoded array: \" \\+ encoded","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/util/StringUtils.java","lineNumber":2567,"sourceCode":"   * or parentheses.\n   *\n   * @param encoded The String encoding an array\n   * @return A String array corresponding to the encoded array\n   */\n  public static String[] decodeArray(String encoded) {\n    if (encoded.isEmpty()) return EMPTY_STRING_ARRAY;\n    char[] chars = encoded.trim().toCharArray();\n\n    //--Parse the String\n    // (state)\n    char quoteCloseChar = (char) 0;\n    List<String> terms = new ArrayList<>();\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 array: \" + encoded); }\n    if(chars[0] == '['){ start += 1; end -= 1; if(chars[end] != ']') throw new IllegalArgumentException(\"Unclosed bracket in encoded array: \" + encoded); }\n    if(chars[0] == '{'){ start += 1; end -= 1; if(chars[end] != '}') throw new IllegalArgumentException(\"Unclosed bracke in encoded array: \" + encoded); }\n    // (finite state automaton)\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) throw new IllegalArgumentException(\"Last character of encoded array is escape character: \" + encoded);\n        current.append(chars[i+1]);\n        i += 1;\n      } else {","sourceCodeStart":2549,"sourceCodeEnd":2585,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/util/StringUtils.java#L2549-L2585","documentation":"Same decoder path for '{'-delimited encoded arrays. If the string starts with '{' the last character must be '}' (note the typo 'bracke' in the message). Otherwise the encoded array is malformed and an IllegalArgumentException is thrown.","triggerScenarios":"Calling the public StringUtils decode method with a string whose first character is '{' but whose last character is not '}' (e.g. \"{a,b\", \"{a,b]\").","commonSituations":"Mixing up brace styles when writing encoded values by hand; a generator that emits '{' but a different closer; truncation during copy-paste or serialization.","solutions":["Append the matching '}' as the final character of the encoded string","Fix the code that builds the encoded string to emit a matching closing brace","Normalize/validate delimiters before decoding","Catch IllegalArgumentException and surface a clear parse failure"],"exampleFix":"// before\nStringUtils.decode(\"{foo,bar\");\n// after\nStringUtils.decode(\"{foo,bar}\");","handlingStrategy":"validation","validationCode":"if (s != null && s.startsWith(\"{\") && !s.endsWith(\"}\")) throw new IllegalArgumentException(\"Encoded array must end with '}': \" + s);","typeGuard":"static boolean isBraceBalanced(String s) { return s != null && s.length() >= 2 && s.charAt(0)=='{' && s.charAt(s.length()-1)=='}'; }","tryCatchPattern":null,"preventionTips":["Use one delimiter style consistently in generators and configs","Validate brace balance before calling the decoder","Beware copy-paste truncation of encoded values"],"tags":["java","string-parsing","malformed-input","illegal-argument"],"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"}