stanfordnlp/CoreNLP · error · IllegalArgumentException
Unclosed paren in encoded array: " + encoded
Error message
Unclosed paren in encoded array: " + encoded
What it means
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.
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
Example fix
// before String enc = "(1,2,3"; // truncated List<String> terms = StringUtils.decodeArray(enc); // after String enc = "(1,2,3)"; List<String> terms = StringUtils.decodeArray(enc);
Defensive patterns
Strategy: validation
Validate before calling
String s = encoded.trim();
if (s.startsWith("(") && !s.endsWith(")")) throw new IllegalArgumentException("Unclosed paren: " + encoded); Try / catch
try {
List<String> terms = StringUtils.decodeArray(encoded);
} catch (IllegalArgumentException e) {
log.error("Bad encoded array: " + e.getMessage());
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.
Related errors
- invalid format: ||
- Dependencies should be for the format 'type(arg-idx…
- Expected left paren!
- Expected right paren!
- Tag did not start with <
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/ef2eadc118094098.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/util/StringUtils.java:2565
/**
* Decode an array encoded as a String. This entails a comma separated value enclosed in brackets
* or parentheses.
*
* @param encoded The String encoding an array
* @return A String array corresponding to the encoded array
*/
public static String[] decodeArray(String encoded) {
if (encoded.isEmpty()) return EMPTY_STRING_ARRAY;
char[] chars = encoded.trim().toCharArray();
//--Parse the String
// (state)
char quoteCloseChar = (char) 0;
List<String> terms = new ArrayList<>();
StringBuilder current = new StringBuilder();
//(start/stop overhead)
int start = 0; int end = chars.length;
if(chars[0] == '('){ start += 1; end -= 1; if(chars[end] != ')') throw new IllegalArgumentException("Unclosed paren in encoded array: " + encoded); }
if(chars[0] == '['){ start += 1; end -= 1; if(chars[end] != ']') throw new IllegalArgumentException("Unclosed bracket in encoded array: " + encoded); }
if(chars[0] == '{'){ start += 1; end -= 1; if(chars[end] != '}') throw new IllegalArgumentException("Unclosed bracke in encoded array: " + encoded); }
// (finite state automaton)
for (int i=start; i<end; i++) {
if (chars[i] == '\r') {
// Ignore funny windows carriage return
continue;
} else if (quoteCloseChar != 0) {
//(case: in quotes)
if(chars[i] == quoteCloseChar){
quoteCloseChar = (char) 0;
}else{
current.append(chars[i]);
}
} else if(chars[i] == '\\'){
//(case: escaped character)
if(i == chars.length - 1) throw new IllegalArgumentException("Last character of encoded array is escape character: " + encoded);
current.append(chars[i+1]);View on GitHub (pinned to 1b7edd19c4)