{"record":{"id":"63dd12a2a6814770","repo":"stanfordnlp/CoreNLP","slug":"runtimeioexception-wrapping-ioexception-from-file","errorCode":null,"errorMessage":"RuntimeIOException wrapping IOException from file open","messagePattern":"RuntimeIOException wrapping IOException from file open","errorType":"exception","errorClass":"RuntimeIOException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/parser/shiftreduce/TreeRecorder.java","lineNumber":33,"sourceCode":" * Useful for seeing the intermediate results of the ShiftReduceParser\n *\n * @author John Bauer\n */\npublic class TreeRecorder implements ParserQueryEval {\n  public enum Mode {\n    BINARIZED, DEBINARIZED\n  };\n\n  private final Mode mode;\n\n  private final BufferedWriter out;\n\n  public TreeRecorder(Mode mode, String filename) {\n    this.mode = mode;\n    try {\n      out = new BufferedWriter(new FileWriter(filename));\n    } catch (IOException e) {\n      throw new RuntimeIOException(e);\n    }\n  }\n\n  public void evaluate(ParserQuery query, Tree gold, PrintWriter pw) {\n    if (!(query instanceof ShiftReduceParserQuery)) {\n      throw new IllegalArgumentException(\"This evaluator only works for the ShiftReduceParser\");\n    }\n    \n    ShiftReduceParserQuery srquery = (ShiftReduceParserQuery) query;\n    try {\n      switch (mode) {\n      case BINARIZED:\n        out.write(srquery.getBestBinarizedParse().toString());\n        break;\n      case DEBINARIZED:\n        out.write(srquery.debinarized.toString());\n        break;\n      default:","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/parser/shiftreduce/TreeRecorder.java#L15-L51","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Verify the parent directory of filename exists and create it (Files.createDirectories) before constructing TreeRecorder","Check the filename is a file, not an existing directory, and the path is correct","Confirm the process user has write permission on the target path","Catch RuntimeIOException around TreeRecorder construction and surface a clear message to the user"],"exampleFix":"// before\nTreeRecorder recorder = new TreeRecorder(TreeRecorder.Mode.WRITE, \"out/trees.txt\");\n// after\njava.nio.file.Files.createDirectories(java.nio.file.Path.of(\"out\"));\nTreeRecorder recorder = new TreeRecorder(TreeRecorder.Mode.WRITE, \"out/trees.txt\");","handlingStrategy":"try-catch","validationCode":"java.nio.file.Path p = java.nio.file.Path.of(filename);\nif (!java.nio.file.Files.isDirectory(p.getParent())) java.nio.file.Files.createDirectories(p.getParent());\nif (java.nio.file.Files.isDirectory(p)) throw new IllegalStateException(\"output path is a directory: \" + p);","typeGuard":null,"tryCatchPattern":"try {\n  TreeRecorder r = new TreeRecorder(mode, filename);\n} catch (RuntimeIOException e) {\n  throw new IllegalStateException(\"Cannot open tree output file \" + filename + \": \" + e.getCause(), e);\n}","preventionTips":["Create parent directories before opening output files","Verify write permissions for the executing user","Prefer local disks over network mounts for large tree dumps"],"tags":["java","io","file-open"],"backgroundTag":"file-open-failed","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}