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

  1. Verify the file exists and is readable: new File(docPath).canRead() before constructing
  2. Use an absolute path or resolve relative paths against the intended base directory
  3. Check the encoding string is a valid charset name (Charset.isSupported(encoding))
  4. If the path is a classpath resource, load it via IOUtils.readerFromClassPath or getResourceAsStream instead
  5. 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

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


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)