stanfordnlp/CoreNLP · error · RuntimeException
Exception reading key file + sentFileName
Error message
Exception reading key file + sentFileName
What it means
In SemanticGraphPrinter.main, any Exception raised while reading and parsing the sentence file (tokenizer, parser, I/O) is wrapped in RuntimeException("Exception reading key file " + sentFileName). It is a generic failure wrapper indicating the key-file reading loop crashed.
Solutions
- Inspect the wrapped cause (e.getCause()) to find the real failure
- Validate the input file is plain text in the expected encoding (UTF-8) before running
- Test the parser on individual sentences to isolate the offending line
- Catch RuntimeException around the reader and process the file line-by-line with per-line error handling
Example fix
// before
printerMain(new String[]{sentFileName}); // crashes whole run on bad line
// after
try {
printerMain(new String[]{sentFileName});
} catch (RuntimeException e) {
logger.warning("Key file failed: " + e.getCause());
} Defensive patterns
Strategy: try-catch
Validate before calling
if (sentFileName != null && new File(sentFileName).canRead()) { ... } Try / catch
try { printerMain(args); } catch (RuntimeException e) { log.severe("Key file processing failed: " + e.getCause()); } Prevention
- Always inspect the wrapped cause exception
- Validate input encoding (UTF-8 plain text) before parsing
- Pre-test sentences individually to isolate failures
When it happens
Trigger: Malformed sentence text that crashes the LexicalizedParser, an I/O error mid-read (disk, encoding), or any runtime exception inside the per-line parse loop.
Common situations: Empty or binary/corrupt input files, unsupported character encodings, parser model issues surfacing on specific sentences.
Understand the failure class
Background: "failed to read file", EACCES, ENOENT and "could not read <path>" errors: when a program can't read a file from disk — this error's family across 49 libraries.
Related errors
- Error creating data exporter
- Dataset could not be loaded
- Error loading classifier from
- edu.stanford.nlp.io.RuntimeIOException
- Bad data format:
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/3ccbcc94d6e5d98c.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/semgraph/SemanticGraphPrinter.java:79
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);
System.out.println(sg.toString());
System.out.println(sg.toCompactString());
if (testGraph.equals("true")) {
SemanticGraph g1 = SemanticGraphFactory.generateCollapsedDependencies(t);
System.out.println("TEST SEMANTIC GRAPH - graph ----------------------------");
System.out.println(g1.toString());
System.out.println("readable ----------------------------");
System.out.println(g1.toString(SemanticGraph.OutputFormat.READABLE));
System.out.println("List of dependencies ----------------------------");
System.out.println(g1.toList());
System.out.println("xml ----------------------------");
System.out.println(g1.toString(SemanticGraph.OutputFormat.XML));View on GitHub (pinned to 1b7edd19c4)