stanfordnlp/CoreNLP · error · IllegalArgumentException
Unclosed bracket in encoded array: " + encoded
Error message
Unclosed bracket in encoded array: " + encoded
What it means
StringUtils' encoded-array decoder (stringToArray-style parsing) expects an array encoded as "(a,b,c)" or "[a,b]". When the string starts with '[' the decoder strips one character from each end and requires the final character to be ']'. If it is not, the encoded array is malformed and this IllegalArgumentException is thrown so the caller fails fast instead of silently mis-parsing.
Solutions
- Inspect the input string and add the missing ']' as the last character
- Ensure the program that generates the encoded string appends the matching close bracket
- Trim stray whitespace/trailing characters before passing the string to the decoder
- Wrap the call in try-catch on IllegalArgumentException and report the malformed input to the user
Example fix
// before
String[] terms = StringUtils.decode("[foo,bar");
// after
String[] terms = StringUtils.decode("[foo,bar]"); Defensive patterns
Strategy: validation
Validate before calling
if (s != null && s.startsWith("[") && !s.endsWith("]")) throw new IllegalArgumentException("Encoded array must end with ']': " + s); Type guard
static boolean isBracketBalanced(String s) { return s != null && s.length() >= 2 && ((s.charAt(0)=='[' && s.charAt(s.length()-1)==']') || (s.charAt(0)=='(' && s.charAt(s.length()-1)==')') || (s.charAt(0)=='{' && s.charAt(s.length()-1)=='}')); } Prevention
- Always emit matching open/close delimiters when building encoded strings
- Trim and validate input before decoding
- Never hand-edit encoded strings without checking the final character
When it happens
Trigger: 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)", "[]x").
Common situations: Hand-built or truncated encoded strings pasted into config files; string truncation by logging/copy-paste; off-by-one string slicing when programmatically building the encoded form; stray characters appended after the closing bracket.
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
- Unclosed bracke in encoded array: " + encoded
- Last character of encoded array is escape character: " +…
- Unclosed bracket in encoded map: " + encoded
- Unclosed paren in encoded map: " + encoded
- Cannot find matching labelled span for
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/79463cc0acd79dd1.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/util/StringUtils.java:2566
* 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]);
i += 1;View on GitHub (pinned to 1b7edd19c4)