stanfordnlp/CoreNLP · error · RuntimeIOException

Cannot find or open + sentFileName

Error message

Cannot find or open  + sentFileName

What it means

SemanticGraphPrinter's main routine wraps an IOException from IOUtils.readerFromString(sentFileName) in a RuntimeIOException("Cannot find or open " + sentFileName). It means the sentence-file argument passed on the command line could not be resolved to a readable reader (missing file, bad path, or invalid URL/classpath spec).

Solutions

  1. Check the file exists and is readable: new File(sentFileName).canRead() before running
  2. Use an absolute path or verify the process working directory
  3. If loading a classpath/URL resource, use the correct IOUtils string syntax
  4. Catch RuntimeIOException around the main call for programmatic use

Example fix

// before
java edu.stanford.nlp.semgraph.SemanticGraphPrinter sents.txt  // typo: sentence.txt
// after
java edu.stanford.nlp.semgraph.SemanticGraphPrinter /abs/path/sentence.txt
Defensive patterns

Strategy: validation

Validate before calling

java.io.File f = new java.io.File(sentFileName); if (!f.isFile() || !f.canRead()) throw new IllegalArgumentException("Missing sentence file: " + sentFileName);

Try / catch

try { printerMain(args); } catch (RuntimeIOException e) { log.severe("Sentence file unreadable: " + args[0]); }

Prevention

When it happens

Trigger: Running SemanticGraphPrinter's main with a filename that does not exist, a path with typos, or a string IOUtils cannot interpret as file/URL/classpath resource.

Common situations: Forgetting to pass the sentence file argument so an option name is treated as a filename; relative paths resolved from the wrong working directory; file lives outside the expected location.

Understand the failure class

Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.

Related errors


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

Appendix: source

Thrown at src/edu/stanford/nlp/semgraph/SemanticGraphPrinter.java:66

    if (load != null) {
      log.info("Load not implemented!");
      return;
    }

    if (sentFileName == null && treeFileName == null) {
      log.info("Usage: java SemanticGraph [-sentFile file|-treeFile file] [-testGraph]");
      Tree t = Tree.valueOf("(ROOT (S (NP (NP (DT An) (NN attempt)) (PP (IN on) (NP (NP (NNP Andres) (NNP Pastrana) (POS 's)) (NN life)))) (VP (VBD was) (VP (VBN carried) (PP (IN out) (S (VP (VBG using) (NP (DT a) (JJ powerful) (NN bomb))))))) (. .)))");
      tb.add(t);
    } else if (treeFileName != null) {
      tb.loadPath(treeFileName);
    } else {
      String[] options = {"-retainNPTmpSubcategories"};
      LexicalizedParser lp = LexicalizedParser.loadModel("/u/nlp/data/lexparser/englishPCFG.ser.gz", options);
      BufferedReader reader = null;
      try {
        reader = IOUtils.readerFromString(sentFileName);
      } catch (IOException e) {
        throw new RuntimeIOException("Cannot find or open " + sentFileName, e);
      }
      try {
        System.out.println("Processing sentence file " + sentFileName);
        for  (String line; (line = reader.readLine()) != null; ) {
          System.out.println("Processing sentence: " + line);
          PTBTokenizer<Word> ptb = PTBTokenizer.newPTBTokenizer(new StringReader(line));
          List<Word> words = ptb.tokenize();
          Tree parseTree = lp.parseTree(words);
          tb.add(parseTree);
        }
        reader.close();
      } catch (Exception e) {
        throw new RuntimeException("Exception reading key file " + sentFileName, e);
      }
    }

    for (Tree t : tb) {
      SemanticGraph sg = SemanticGraphFactory.generateUncollapsedDependencies(t);

View on GitHub (pinned to 1b7edd19c4)