stanfordnlp/CoreNLP · error · RuntimeException
File not found:
Error message
File not found:
What it means
getParserFromSerializedFile could not open the serialized parser file: java.io.FileNotFoundException was caught and rethrown as RuntimeException("File not found: ..."). The requested model path/URL does not exist or is not readable.
Solutions
- Verify the exact path in the message exists: ls <path> / resolve it relative to the process working directory
- Use a fully qualified path or load from classpath resource (e.g. "/edu/stanford/nlp/models/lexparser/englishPCFG.ser.gz")
- Install/download the matching models package (Stanford CoreNLP models jar or zip) that contains the grammar
- Check file permissions and that the user running the JVM can read it
Example fix
// before
LexicalizedParser lp = LexicalizedParser.loadModel("englishPCFG.ser.gz"); // only works if cwd is right
// after
LexicalizedParser lp = LexicalizedParser.loadModel("/models/englishPCFG.ser.gz"); // absolute path Defensive patterns
Strategy: validation
Validate before calling
java.io.File f = new java.io.File(modelPath);
if (!f.isFile() || !f.canRead()) throw new IllegalArgumentException("Parser model missing/unreadable: " + f.getAbsolutePath()); Try / catch
try {
LexicalizedParser lp = LexicalizedParser.loadModel(path);
} catch (RuntimeException e) {
if (e.getCause() instanceof FileNotFoundException) {
throw new IllegalStateException("Model file not found: " + path + " (cwd=" + new File(".").getAbsolutePath() + ")", e);
}
throw e;
} Prevention
- Log the resolved absolute path and working directory before loading
- Ship models on the classpath and load via classpath resource paths
- Add the models artifact to your build (CoreNLP models jar) so models always exist
When it happens
Trigger: Calling LexicalizedParser.loadModel(path) or the -model CLI option with a path that does not exist, a typo'd filename, a path relative to the wrong working directory, or an inaccessible URL/classpath resource.
Common situations: Running from a different working directory than assumed in the script; model not extracted from a zip/tarball; missing model artifact dependency (e.g. models jar not on classpath); typo like englishPCFG.ser.gx; file removed after a clean build.
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
- Couldn't read function word file
- Error loading classifier from
- Couldn't load classifier from
- format error in embeddings
- format error unexpected featureFactory line:
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/89c8f02152ebef19.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/parser/lexparser/LexicalizedParser.java:580
return null;
}
public static LexicalizedParser getParserFromSerializedFile(String serializedFileOrUrl) {
try {
Timing tim = new Timing();
ObjectInputStream in = IOUtils.readStreamFromString(serializedFileOrUrl);
LexicalizedParser pd = loadModel(in);
in.close();
log.info("Loading parser from serialized file " + serializedFileOrUrl + " ... done [" + tim.toSecondsString() + " sec].");
return pd;
} catch (InvalidClassException ice) {
// For this, it's not a good idea to continue and try it as a text file!
throw new RuntimeException("Invalid class in file: " + serializedFileOrUrl, ice);
} catch (FileNotFoundException fnfe) {
// For this, it's not a good idea to continue and try it as a text file!
throw new RuntimeException("File not found: " + serializedFileOrUrl, fnfe);
} catch (StreamCorruptedException sce) {
// suppress error message, on the assumption that we've really got
// a text grammar, and that'll be tried next
log.info("Attempting to load " + serializedFileOrUrl +
" as a serialized grammar caused error below, but this may just be because it's a text grammar!");
log.info(sce);
} catch (Exception e) {
log.error(e);
}
return null;
}
private static void printOptions(boolean train, Options op) {
op.display();
if (train) {
op.trainOptions.display();
} else {View on GitHub (pinned to 1b7edd19c4)