stanfordnlp/CoreNLP · warning
e
Error message
e
What it means
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.
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
Example fix
// before java edu.stanford.nlp.trees.tregex.TregexPattern 'NP < NN' corpus.mrg // after (file first verified) ls -l corpus.mrg && java edu.stanford.nlp.trees.tregex.TregexPattern -f corpus.mrg 'NP < NN'
Defensive patterns
Strategy: validation
Validate before calling
File f = new File(args[filesIndex]);
if (!f.isFile() || !f.canRead()) throw new IllegalArgumentException("unreadable tree file: " + f); Try / catch
try {
// run TregexPattern matching
} catch (IOException e) {
log.error("Failed reading input trees", e);
System.exit(1);
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
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
- No input file provided (use -textFile)
- Couldn't read TokensRegexNER from
- Cannot find or open + sentFileName
- File problem
- Error creating ChineseMaxentLexicon
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/24aedbef613f37e1.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/trees/tregex/TregexPattern.java:815
int last = args.length - 1;
errPW.println("Reading trees from file(s) " + args[last]);
TreeReaderFactory trf = getTreeReaderFactory(treeReaderFactoryClassName);
treebank = new DiskTreebank(trf, encoding);
treebank.loadPath(args[last], extension, true);
}
TRegexTreeVisitor vis = new TRegexTreeVisitor(p, handles, encoding);
treebank.apply(vis);
Timing.endTime();
if (TRegexTreeVisitor.printMatches) {
errPW.println("There were " + vis.numMatches() + " matches in total.");
}
if (TRegexTreeVisitor.printNumMatchesToStdOut) {
System.out.println(vis.numMatches());
}
} catch (IOException e) {
log.warn(e);
} catch (TregexParseException e) {
errPW.println("Error parsing expression: " + args[0]);
errPW.println("Parse exception: " + e);
}
}
private static TreeReaderFactory getTreeReaderFactory(String treeReaderFactoryClassName) {
TreeReaderFactory trf = new TRegexTreeReaderFactory();
if (treeReaderFactoryClassName != null) {
try {
trf = (TreeReaderFactory) Class.forName(treeReaderFactoryClassName).getDeclaredConstructor().newInstance();
} catch (Exception e) {
throw new RuntimeException("Error occurred while constructing TreeReaderFactory: " + e);
}
}
return trf;
}
View on GitHub (pinned to 1b7edd19c4)