{"record":{"id":"24aedbef613f37e1","repo":"stanfordnlp/CoreNLP","slug":"e-24aedb","errorCode":null,"errorMessage":"e","messagePattern":"e","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/edu/stanford/nlp/trees/tregex/TregexPattern.java","lineNumber":815,"sourceCode":"        int last = args.length - 1;\n        errPW.println(\"Reading trees from file(s) \" + args[last]);\n        TreeReaderFactory trf = getTreeReaderFactory(treeReaderFactoryClassName);\n\n        treebank = new DiskTreebank(trf, encoding);\n        treebank.loadPath(args[last], extension, true);\n      }\n      TRegexTreeVisitor vis = new TRegexTreeVisitor(p, handles, encoding);\n\n      treebank.apply(vis);\n      Timing.endTime();\n      if (TRegexTreeVisitor.printMatches) {\n        errPW.println(\"There were \" + vis.numMatches() + \" matches in total.\");\n      }\n      if (TRegexTreeVisitor.printNumMatchesToStdOut) {\n        System.out.println(vis.numMatches());\n      }\n    } catch (IOException e) {\n      log.warn(e);\n    } catch (TregexParseException e) {\n      errPW.println(\"Error parsing expression: \" + args[0]);\n      errPW.println(\"Parse exception: \" + e);\n    }\n  }\n\n  private static TreeReaderFactory getTreeReaderFactory(String treeReaderFactoryClassName) {\n    TreeReaderFactory trf = new TRegexTreeReaderFactory();\n    if (treeReaderFactoryClassName != null) {\n      try {\n        trf = (TreeReaderFactory) Class.forName(treeReaderFactoryClassName).getDeclaredConstructor().newInstance();\n      } catch (Exception e) {\n        throw new RuntimeException(\"Error occurred while constructing TreeReaderFactory: \" + e);\n      }\n    }\n    return trf;\n  }\n","sourceCodeStart":797,"sourceCodeEnd":833,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/trees/tregex/TregexPattern.java#L797-L833","documentation":"TregexPattern's command-line main catches IOException from tree reading and logs it via log.warn(e), then continues exiting normally. It signals that reading the input trees (from a file or stdin) failed mid-way — the match counts printed reflect only the trees read before the failure.","triggerScenarios":"Running the Tregex main with -f/file arguments pointing at a missing or unreadable tree file, or the input stream ending with an IO error while PennTreeReader reads trees.","commonSituations":"Typo in the input filename; wrong working directory; piping an empty/closed stdin; file removed or permissions changed while running; reading a directory instead of a file.","solutions":["Verify the input file path exists and is readable (ls -l / cat the file first)","Run from the correct working directory or pass an absolute path to -f","Check file permissions and that the path is a regular file, not a directory","If strict behavior is wanted, copy the main logic and rethrow the IOException instead of warn-and-continue"],"exampleFix":"// before\njava edu.stanford.nlp.trees.tregex.TregexPattern 'NP < NN' corpus.mrg\n// after (file first verified)\nls -l corpus.mrg && java edu.stanford.nlp.trees.tregex.TregexPattern -f corpus.mrg 'NP < NN'","handlingStrategy":"validation","validationCode":"File f = new File(args[filesIndex]);\nif (!f.isFile() || !f.canRead()) throw new IllegalArgumentException(\"unreadable tree file: \" + f);","typeGuard":null,"tryCatchPattern":"try {\n  // run TregexPattern matching\n} catch (IOException e) {\n  log.error(\"Failed reading input trees\", e);\n  System.exit(1);\n}","preventionTips":["Check input file existence/readability before invoking TregexPattern","Use absolute paths or verify the JVM working directory","Prefer reading via an explicit Reader you control so IO failures surface with a clear filename"],"tags":["io","cli","nlp","file-not-found"],"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"}