stanfordnlp/CoreNLP · error · ParserException
Expected left paren!
Error message
Expected left paren!
What it means
SemanticGraph's text-format parser throws ParserException("Expected left paren!") in readLeftBracket when the next non-whitespace character is not a recognized opening bracket ('(' / '['). It means the string being deserialized does not start a node entry as required by the SemanticGraph text format.
Solutions
- Feed the parser only strings produced by SemanticGraph.toString() (RECURSIVE format)
- Trim/pre-validate the input starts with '(' or '[' before parsing
- Check for file corruption or truncation in saved graph files
- Catch ParserException around deserialization of untrusted input
Example fix
// before
SemanticGraph sg = SemanticGraph.valueOf(userLine.trim());
// after
String s = userLine.trim();
if (!s.startsWith("(") && !s.startsWith("[")) {
throw new IllegalArgumentException("Not a serialized SemanticGraph: " + s);
}
SemanticGraph sg = SemanticGraph.valueOf(s); Defensive patterns
Strategy: validation
Validate before calling
String s = input.trim(); if (s.startsWith("(") || s.startsWith("[")) { SemanticGraph sg = SemanticGraph.valueOf(s); } Try / catch
try { sg = SemanticGraph.valueOf(s); } catch (ParserException e) { log.warn("Bad serialized graph: " + s, e); } Prevention
- Only parse strings produced by SemanticGraph.toString()
- Check bracket balance before parsing
- Validate file integrity of stored graph dumps
When it happens
Trigger: SemanticGraph.valueOf(...) or the parser reading a string whose first token is not '(' or '[' — e.g. empty string, prose, a dependencies list without brackets, or output from a different format.
Common situations: Feeding toString(LIST) or human-readable output back into valueOf; truncation/corruption of a serialized graph; parsing a line with leading garbage or wrong locale whitespace characters.
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 right 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/cebfa05042e96f3d.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/semgraph/SemanticGraph.java:2017
emptyIndex = 0;
}
return new Triple<>(word, index, emptyIndex);
}
}
private Integer getNextFreeIndex() {
int i = 0;
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 == '[';View on GitHub (pinned to 1b7edd19c4)