stanfordnlp/CoreNLP · error · ParserException
Expected right paren!
Error message
Expected right paren!
What it means
readRightBracket throws ParserException("Expected right paren!") when, while parsing a serialized SemanticGraph, the character after a node/relation entry is not a closing bracket (')' or ']'). The serialized string is structurally incomplete or malformed.
Solutions
- Verify the serialized string is complete and balanced (count brackets) before parsing
- Round-trip test: only parse strings produced by the same parser version's toString()
- Read the entire serialized graph (not line-by-line) before handing it to the parser
- Catch ParserException and log the offending string for diagnosis
Example fix
// before
SemanticGraph sg = SemanticGraph.valueOf(line); // line truncated
// after
String full = fullGraphText.toString(); // accumulate complete text first
if (full.chars().filter(c -> c == '(').count() != full.chars().filter(c -> c == ')').count()) {
throw new IllegalArgumentException("Unbalanced brackets");
}
SemanticGraph sg = SemanticGraph.valueOf(full); Defensive patterns
Strategy: validation
Validate before calling
if (s.chars().filter(c -> c=='(').count() == s.chars().filter(c -> c==')').count() && s.trim().endsWith(")")) { SemanticGraph sg = SemanticGraph.valueOf(s); } Try / catch
try { sg = SemanticGraph.valueOf(s); } catch (ParserException e) { log.warn("Truncated graph text", e); } Prevention
- Read the complete serialized graph before parsing (avoid line-by-line splitting)
- Never hand-edit serialized graph text
- Round-trip test serialization with the same parser version
When it happens
Trigger: Deserializing a SemanticGraph from text where an entry is truncated mid-way, a bracket was stripped, or two graphs/lines were concatenated incorrectly.
Common situations: Line-based readers cutting a multi-line serialized graph in half; manual editing of .ser/text graph dumps; regex preprocessing that removed closing parens.
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
- Expected left paren!
- Bad number put into wordToNumber. Word is: \"" + input +…
- Error in wordToNumber function.
- Bad number put into wordToNumber. Word is: \"" + curPart +…
- Doesn't do k best yet
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/8abb2153a31c7e27.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/semgraph/SemanticGraph.java:2025
while (indexesUsed.containsKey(i))
i++;
return i;
}
private void readLeftBracket() {
// System.out.println("Read left.");
readWhiteSpace();
char ch = read();
if (!isLeftBracket(ch))
throw new ParserException("Expected left paren!");
}
private void readRightBracket() {
// System.out.println("Read right.");
readWhiteSpace();
char ch = read();
if (!isRightBracket(ch))
throw new ParserException("Expected right paren!");
}
private void readRelnSeparator() {
readWhiteSpace();
if (isRelnSeparator(peek()))
read();
}
private static boolean isLeftBracket(char ch) {
return ch == '[';
}
private static boolean isRightBracket(char ch) {
return ch == ']';
}
private static boolean isRelnSeparator(char ch) {
return ch == '>';View on GitHub (pinned to 1b7edd19c4)