stanfordnlp/CoreNLP · error · IOException

Error on line

Error message

Error on line 

What it means

readData in BinaryGrammar parses the grammar section of a text-format parser grammar file, constructing a BinaryRule from each non-empty line. If BinaryRule's constructor throws for any line (malformed rule syntax, state names absent from the state Index), the original exception is swallowed and replaced with a bare IOException("Error on line N"), losing the cause.

Solutions

  1. Open the grammar file and inspect/fix the rule on the reported line number (lineNum counts from 1 within the binary-grammar section)
  2. Regenerate the grammar file with the same version of the parser that will read it instead of hand-editing
  3. Temporarily recompile readData to wrap 'e' (throw new IOException("Error on line " + lineNum, e)) to see the real parse failure
  4. Verify you are loading the intended .txt/.gz grammar path, not a different or stale file

Example fix

// before (opaque)
throw new IOException("Error on line " + lineNum);
// after (preserve cause)
throw new IOException("Error on line " + lineNum, e);
Defensive patterns

Strategy: validation

Validate before calling

// pre-scan grammar lines before readData
int n = 1;
for (String line : Files.readAllLines(grammarPath)) {
  if (!line.isEmpty() && line.split("\\s+").length != 3)
    throw new IllegalArgumentException("Bad binary rule at line " + n + ": " + line);
  n++;
}

Try / catch

try { bg.readData(in); } catch (IOException e) { log.error("Grammar file malformed at " + e.getMessage() + " — fix or regenerate grammar file"); }

Prevention

When it happens

Trigger: Loading a parser from a text grammar file (getParserFromTextFile) where a line in the binary-rules section is not a valid "parent @ left right" style rule or references state names not present in the grammar's state index.

Common situations: Hand-edited or truncated grammar/text parser files, files from a different grammar format or older Stanford Parser version, wrong file fed to Options/lexparser load path.

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

Appendix: source

Thrown at src/edu/stanford/nlp/parser/lexparser/BinaryGrammar.java:265

  }

  /**
   * Populates data in this BinaryGrammar from the character stream
   * given by the Reader r.
   *
   * @param in Where input is read from
   * @throws IOException If format is bung
   */
  public void readData(BufferedReader in) throws IOException {
    //if (Test.verbose) log.info(">> readData");
    String line;
    int lineNum = 1;
    line = in.readLine();
    while (line != null && line.length() > 0) {
      try {
        addRule(new BinaryRule(line, index));
      } catch (Exception e) {
        throw new IOException("Error on line " + lineNum);
      }
      lineNum++;
      line = in.readLine();
    }
    splitRules();
  }

  /**
   * Writes out data from this Object to the Writer w.
   *
   * @param w Where output is written
   * @throws IOException If data can't be written
   */
  public void writeData(Writer w) throws IOException {
    PrintWriter out = new PrintWriter(w);
    for (BinaryRule br : this) {
      out.println(br.toString(index));
    }

View on GitHub (pinned to 1b7edd19c4)