{"record":{"id":"ef2eadc118094098","repo":"stanfordnlp/CoreNLP","slug":"unclosed-paren-in-encoded-array-encoded","errorCode":null,"errorMessage":"Unclosed paren in encoded array: \" + encoded","messagePattern":"Unclosed paren in encoded array: \" \\+ encoded","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/util/StringUtils.java","lineNumber":2565,"sourceCode":"  /**\n   * Decode an array encoded as a String. This entails a comma separated value enclosed in brackets\n   * 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]);","sourceCodeStart":2547,"sourceCodeEnd":2583,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/util/StringUtils.java#L2547-L2583","documentation":"When decoding a parenthesized encoded array string, StringUtils checks that if the string starts with '(' it also ends with ')'. If the closing parenthesis is missing it throws IllegalArgumentException('Unclosed paren in encoded array: <encoded>'). Bracket and brace variants exist with similar messages.","triggerScenarios":"Calling the encoded-array parser (e.g. stringToKey/decode style API in StringUtils) with a string that starts with '(' but does not end with ')', such as '(1,2,3' or a string cut off mid-expression.","commonSituations":"Truncated files or logs that were cut off; manual string edits dropping the final char; concatenation code that forgot the closing paren; copying encoded values from output that was line-wrapped.","solutions":["Supply the complete string including the closing parenthesis","Validate balance before parsing: check s.startsWith(\"(\") implies s.endsWith(\")\")","Regenerate the encoded string with the library's encoder instead of reconstructing it manually"],"exampleFix":"// before\nString enc = \"(1,2,3\"; // truncated\nList<String> terms = StringUtils.decodeArray(enc);\n// after\nString enc = \"(1,2,3)\";\nList<String> terms = StringUtils.decodeArray(enc);","handlingStrategy":"validation","validationCode":"String s = encoded.trim();\nif (s.startsWith(\"(\") && !s.endsWith(\")\")) throw new IllegalArgumentException(\"Unclosed paren: \" + encoded);","typeGuard":null,"tryCatchPattern":"try {\n  List<String> terms = StringUtils.decodeArray(encoded);\n} catch (IllegalArgumentException e) {\n  log.error(\"Bad encoded array: \" + e.getMessage());\n}","preventionTips":["Never truncate encoded strings when storing or copying them","Verify balancing of '(', '[', '{' wrappers before decoding","Produce encoded arrays with the library's own encoder rather than manual string building"],"tags":["java","parsing","format"],"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-15T23:17:13.987Z"}