stanfordnlp/CoreNLP · error · RuntimeException

Could not create

Error message

Could not create ${dir}

What it means

FileSystem.mkdirOrFail() calls File.mkdirs() and throws RuntimeException if it returns false, after logging the failure. Java's mkdirs() returns false when the directory (and any needed parents) could not be created.

Solutions

  1. Check/write permissions on the parent directory; run with sufficient privileges or pick a writable path.
  2. Verify no regular file exists at the target path (or a parent component); remove/rename it.
  3. Confirm the path is valid on the OS (illegal characters, length limits).
  4. Use plain File.mkdirs() with your own error handling if failure should be tolerated.

Example fix

// before
FileSystem.mkdirOrFail(new File("/data")); // no permission
// after
File dir = new File("/data");
if (!dir.exists() && !dir.mkdirs()) {
  throw new IllegalStateException("Cannot create " + dir + " in cwd=" + new File(".").getAbsolutePath());
}
Defensive patterns

Strategy: validation

Validate before calling

File parent = dir.getAbsoluteFile().getParentFile();
if (parent != null && !parent.canWrite()) throw new IllegalStateException("Cannot write in " + parent);
if (dir.exists() && !dir.isDirectory()) throw new IllegalStateException("Occupied by file: " + dir);

Try / catch

try {
  FileSystem.mkdirOrFail(dir);
} catch (RuntimeException e) {
  log.severe("mkdir failed for " + dir + ": " + e.getMessage());
}

Prevention

When it happens

Trigger: Calling mkdirOrFail(dir) when a parent path component exists as a regular file, the user lacks write permission on the parent, the path is invalid for the OS, or the directory already exists as a non-directory.

Common situations: Output directories on read-only mounts or containers; a stale file occupying the target path; typos in absolute paths (/vs missing drive); running as unprivileged user expecting to write to system paths.

Understand the failure class

Background: mkdir permission denied (EACCES): failed to create directory errors explained — this error's family across 32 libraries.

Related errors


AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10). Data as JSON: /api/errors/c87bdfa48c93b756. Report an issue: GitHub.

Appendix: source

Thrown at src/edu/stanford/nlp/io/FileSystem.java:127

    
    return firstLine.length() > 0;
  }
  
  /**
   * Make the given directory or throw a RuntimeException
   */
  public static void mkdirOrFail(String dir) {
    mkdirOrFail(new File(dir));
  }

  /**
   * Make the given directory or throw a RuntimeException
   */
  public static void mkdirOrFail(File dir) {
    if (!dir.mkdirs()) {
      String error = "Could not create " + dir;
      log.info(error);
      throw new RuntimeException(error);
    }
  }

  public static void checkExistsOrFail(File file) {
    if (!file.exists()) {
      String error = "Output path " + file + " does not exist";
      log.info(error);
      throw new RuntimeException(error);
    }
  }

  public static void checkNotExistsOrFail(File file) {
    if (file.exists()) {
      String error = "Output path " + file + " already exists";
      log.info(error);
      throw new RuntimeException(error);
    }
  }

View on GitHub (pinned to 1b7edd19c4)