stanfordnlp/CoreNLP · error · ParserException

Expected left paren!

Error message

Expected left paren!

What it means

StringParsingTask.readLeftParen reads whitespace and then expects the next character to be an opening parenthesis '(' during parsing of an encoded string form. If the character is not a left paren it throws ParserException('Expected left paren!'), signaling the input string does not match the expected grammatical format.

Solutions

  1. Ensure the input string is wrapped in the expected parenthesized form, e.g. '(a,b)'
  2. Validate the input format before parsing (starts with '(' and ends with ')')
  3. Regenerate the data from the library's own writer/encoder instead of hand-editing

Example fix

// before
String input = "a,b"; // missing parens
// after
String input = "(a,b)";
Defensive patterns

Strategy: validation

Validate before calling

String t = input.trim();
if (!t.startsWith("(")) throw new IllegalArgumentException("Encoded value must start with '(': " + input);

Try / catch

try {
  task.parse();
} catch (ParserException e) {
  log.error("Malformed encoded value '" + input + "': " + e.getMessage());
}

Prevention

When it happens

Trigger: Invoking a parser built on StringParsingTask (e.g. parsing an IntUni/Pair-style encoded value) whose input does not start with '(' after optional whitespace, such as feeding a value without the surrounding parentheses the parser requires.

Common situations: Malformed serialized values or cached results produced by a different format/version; hand-edited data files where parentheses were dropped; passing raw values where parenthesized expressions are expected.

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/c81c4839324bf12e. Report an issue: GitHub.

Appendix: source

Thrown at src/edu/stanford/nlp/util/StringParsingTask.java:90

      ch = read();
      while (Character.isJavaIdentifierPart(ch) && !isEOF) {
        sb.append(ch);
        ch = read();
      }
    }
    unread();
    // log.info("Read text: ["+sb+"]");
    return sb.toString().intern();
  }

  // .....................................................................

  protected void readLeftParen() {
    // System.out.println("Read left.");
    readWhiteSpace();
    char ch = read();
    if (!isLeftParen(ch))
      throw new ParserException("Expected left paren!");
  }

  protected void readRightParen() {
    // System.out.println("Read right.");
    readWhiteSpace();
    char ch = read();
    if (!isRightParen(ch)) 
      throw new ParserException("Expected right paren!");
  }

  protected void readDot() {
    readWhiteSpace();
    if (isDot(peek())) read();
  }

  protected void readWhiteSpace() {
    char ch = read();
    while (isWhiteSpace(ch) && !isEOF()) {

View on GitHub (pinned to 1b7edd19c4)