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

  1. Feed the parser only strings produced by SemanticGraph.toString() (RECURSIVE format)
  2. Trim/pre-validate the input starts with '(' or '[' before parsing
  3. Check for file corruption or truncation in saved graph files
  4. 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

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


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)