stanfordnlp/CoreNLP · error · RuntimeIOException

RuntimeIOException wrapping IOException from file open

Error message

RuntimeIOException wrapping IOException from file open

What it means

TreeRecorder's constructor opens a BufferedWriter on the given filename for writing parse trees. Java's FileWriter throws a checked IOException if the file cannot be opened, and this library intentionally converts it into an unchecked RuntimeIOException so callers of the parser pipeline don't need checked-exception handling. It is thrown directly from the TreeRecorder(mode, filename) constructor.

Solutions

  1. Verify the parent directory of filename exists and create it (Files.createDirectories) before constructing TreeRecorder
  2. Check the filename is a file, not an existing directory, and the path is correct
  3. Confirm the process user has write permission on the target path
  4. Catch RuntimeIOException around TreeRecorder construction and surface a clear message to the user

Example fix

// before
TreeRecorder recorder = new TreeRecorder(TreeRecorder.Mode.WRITE, "out/trees.txt");
// after
java.nio.file.Files.createDirectories(java.nio.file.Path.of("out"));
TreeRecorder recorder = new TreeRecorder(TreeRecorder.Mode.WRITE, "out/trees.txt");
Defensive patterns

Strategy: try-catch

Validate before calling

java.nio.file.Path p = java.nio.file.Path.of(filename);
if (!java.nio.file.Files.isDirectory(p.getParent())) java.nio.file.Files.createDirectories(p.getParent());
if (java.nio.file.Files.isDirectory(p)) throw new IllegalStateException("output path is a directory: " + p);

Try / catch

try {
  TreeRecorder r = new TreeRecorder(mode, filename);
} catch (RuntimeIOException e) {
  throw new IllegalStateException("Cannot open tree output file " + filename + ": " + e.getCause(), e);
}

Prevention

When it happens

Trigger: Calling new TreeRecorder(Mode.WRITE, filename) (or the equivalent evaluator wiring) where filename's directory does not exist, the path is a directory, or the process lacks write permission.

Common situations: Typo in an -output/-evalOutput path passed to a parser training/eval script; output directory not yet created; running as a user without write access; disk full on the target volume.

Understand the failure class

Background: "open() failed", "failed to open file", "cannot create file" — what a file open error means and how to fix it — this error's family across 42 libraries.

Related errors


AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10). Data as JSON: /api/errors/63dd12a2a6814770. Report an issue: GitHub.

Appendix: source

Thrown at src/edu/stanford/nlp/parser/shiftreduce/TreeRecorder.java:33

 * Useful for seeing the intermediate results of the ShiftReduceParser
 *
 * @author John Bauer
 */
public class TreeRecorder implements ParserQueryEval {
  public enum Mode {
    BINARIZED, DEBINARIZED
  };

  private final Mode mode;

  private final BufferedWriter out;

  public TreeRecorder(Mode mode, String filename) {
    this.mode = mode;
    try {
      out = new BufferedWriter(new FileWriter(filename));
    } catch (IOException e) {
      throw new RuntimeIOException(e);
    }
  }

  public void evaluate(ParserQuery query, Tree gold, PrintWriter pw) {
    if (!(query instanceof ShiftReduceParserQuery)) {
      throw new IllegalArgumentException("This evaluator only works for the ShiftReduceParser");
    }
    
    ShiftReduceParserQuery srquery = (ShiftReduceParserQuery) query;
    try {
      switch (mode) {
      case BINARIZED:
        out.write(srquery.getBestBinarizedParse().toString());
        break;
      case DEBINARIZED:
        out.write(srquery.debinarized.toString());
        break;
      default:

View on GitHub (pinned to 1b7edd19c4)