{"record":{"id":"f75edba5e3d0a7af","repo":"stanfordnlp/CoreNLP","slug":"cannot-find-or-open-sentfilename","errorCode":null,"errorMessage":"Cannot find or open  + sentFileName","messagePattern":"Cannot find or open  \\+ sentFileName","errorType":"exception","errorClass":"RuntimeIOException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/semgraph/SemanticGraphPrinter.java","lineNumber":66,"sourceCode":"    if (load != null) {\n      log.info(\"Load not implemented!\");\n      return;\n    }\n\n    if (sentFileName == null && treeFileName == null) {\n      log.info(\"Usage: java SemanticGraph [-sentFile file|-treeFile file] [-testGraph]\");\n      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))))))) (. .)))\");\n      tb.add(t);\n    } else if (treeFileName != null) {\n      tb.loadPath(treeFileName);\n    } else {\n      String[] options = {\"-retainNPTmpSubcategories\"};\n      LexicalizedParser lp = LexicalizedParser.loadModel(\"/u/nlp/data/lexparser/englishPCFG.ser.gz\", options);\n      BufferedReader reader = null;\n      try {\n        reader = IOUtils.readerFromString(sentFileName);\n      } catch (IOException e) {\n        throw new RuntimeIOException(\"Cannot find or open \" + sentFileName, e);\n      }\n      try {\n        System.out.println(\"Processing sentence file \" + sentFileName);\n        for  (String line; (line = reader.readLine()) != null; ) {\n          System.out.println(\"Processing sentence: \" + line);\n          PTBTokenizer<Word> ptb = PTBTokenizer.newPTBTokenizer(new StringReader(line));\n          List<Word> words = ptb.tokenize();\n          Tree parseTree = lp.parseTree(words);\n          tb.add(parseTree);\n        }\n        reader.close();\n      } catch (Exception e) {\n        throw new RuntimeException(\"Exception reading key file \" + sentFileName, e);\n      }\n    }\n\n    for (Tree t : tb) {\n      SemanticGraph sg = SemanticGraphFactory.generateUncollapsedDependencies(t);","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/semgraph/SemanticGraphPrinter.java#L48-L84","documentation":"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).","triggerScenarios":"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.","commonSituations":"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.","solutions":["Check the file exists and is readable: new File(sentFileName).canRead() before running","Use an absolute path or verify the process working directory","If loading a classpath/URL resource, use the correct IOUtils string syntax","Catch RuntimeIOException around the main call for programmatic use"],"exampleFix":"// before\njava edu.stanford.nlp.semgraph.SemanticGraphPrinter sents.txt  // typo: sentence.txt\n// after\njava edu.stanford.nlp.semgraph.SemanticGraphPrinter /abs/path/sentence.txt","handlingStrategy":"validation","validationCode":"java.io.File f = new java.io.File(sentFileName); if (!f.isFile() || !f.canRead()) throw new IllegalArgumentException(\"Missing sentence file: \" + sentFileName);","typeGuard":null,"tryCatchPattern":"try { printerMain(args); } catch (RuntimeIOException e) { log.severe(\"Sentence file unreadable: \" + args[0]); }","preventionTips":["Verify file existence/permissions before invoking","Use absolute paths or confirm the working directory","Don't let option strings be misinterpreted as filenames"],"tags":["java","io","file-not-found","cli"],"backgroundTag":"file-not-found","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"}