stanfordnlp/CoreNLP · error · RuntimeIOException
: Could not open path
Error message
%s: Could not open path %s
What it means
When the docPath is non-null but IOUtils.readerFromString(docPath, encoding) throws an IOException, the constructor rethrows it as a RuntimeIOException formatted as "<ClassName>: Could not open path <path>". This means the path could not be opened as a readable character stream — the file is missing, unreadable, or the encoding is invalid.
Solutions
- Verify the file exists and is readable: new File(docPath).canRead() before constructing
- Use an absolute path or resolve relative paths against the intended base directory
- Check the encoding string is a valid charset name (Charset.isSupported(encoding))
- If the path is a classpath resource, load it via IOUtils.readerFromClassPath or getResourceAsStream instead
- Catch RuntimeIOException around construction to surface the original IOException cause
Example fix
// before
DocumentPreprocessor dp = new DocumentPreprocessor("data/input.txt", DocType.Plain, "UTF-8");
// after
File f = new File("data/input.txt");
if (!f.isFile() || !f.canRead()) {
throw new FileNotFoundException("Input not readable: " + f.getAbsolutePath());
}
DocumentPreprocessor dp = new DocumentPreprocessor(f.getAbsolutePath(), DocType.Plain, "UTF-8"); Defensive patterns
Strategy: validation
Validate before calling
File f = new File(docPath);
if (!f.isFile()) throw new FileNotFoundException("Not a file: " + f.getAbsolutePath());
if (!f.canRead()) throw new IOException("No read permission: " + f.getAbsolutePath());
if (!Charset.isSupported(encoding)) throw new UnsupportedEncodingException(encoding); Try / catch
try {
DocumentPreprocessor dp = new DocumentPreprocessor(docPath, DocType.Plain, "UTF-8");
} catch (RuntimeIOException e) {
if (e.getMessage() != null && e.getMessage().contains("Could not open path")) {
throw new InputOpenException("Cannot open document: " + docPath, e.getCause());
}
throw e;
} Prevention
- Check canRead()/isFile() before constructing the preprocessor
- Resolve relative paths against a known base directory and log the absolute path on failure
- Validate charset names with Charset.isSupported
- In containers, verify the input volume is mounted at the expected path
When it happens
Trigger: Calling new DocumentPreprocessor(docPath, docType, encoding) with a path that does not exist, points to a directory, lacks read permission, has a malformed URL/file: syntax, or an unsupported encoding name.
Common situations: Typo'd or relative path resolved against the wrong working directory; file deleted or not yet generated; running in a container where the input volume is not mounted; unsupported charset string like "utf8" misspellings on strict JVMs.
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 ChineseMaxentLexicon
- Could not read from double initial LOP weights file
- Error reading threshold file
- Couldn't read RegexNER from " + mapping
- cp: cannot copy to directory
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/2d7020e30bedf214.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/process/DocumentPreprocessor.java:140
/**
* Constructs a preprocessor from a file at a path, which can be either
* a filesystem location, a classpath entry, or a URL.
*
* @param docPath The path
* @param encoding The character encoding used by Readers
*/
public DocumentPreprocessor(String docPath, DocType t, String encoding) {
if (docPath == null) {
throw new IllegalArgumentException("Cannot open null document path!");
}
docType = t;
try {
inputReader = IOUtils.readerFromString(docPath, encoding);
} catch (IOException ioe) {
throw new RuntimeIOException(String.format("%s: Could not open path %s", this.getClass().getName(), docPath),
ioe);
}
}
/**
* Set whether or not the tokenizer keeps empty sentences in
* whitespace mode. Useful for programs that want to echo blank
* lines. Not relevant for the non-whitespace model.
*/
public void setKeepEmptySentences(boolean keepEmptySentences) {
this.keepEmptySentences = keepEmptySentences;
}
/**
* Sets the end-of-sentence delimiters.
* <p>
* For newline tokenization, use the argument {"\n"}.
*View on GitHub (pinned to 1b7edd19c4)