stanfordnlp/CoreNLP · critical · IllegalArgumentException

You're trying to delete

Error message

You're trying to delete <file>! I _really_ don't think you want to do that...

What it means

IOUtils.deleteRecursively maintains a hardcoded blocklist (blockListPathsToRemove) of critical paths such as /, /tmp, /usr, /var and similar. If the requested File's path is on that list, it throws this IllegalArgumentException instead of deleting an entire system tree.

Solutions

  1. Pass a specific application data directory, not a root or system path
  2. Log and validate the path before calling deleteRecursively; refuse empty/relative paths
  3. If you truly must delete a blocked path, do it manually (rm -rf) after review — do not bypass the guard

Example fix

// before
IOUtils.deleteRecursively(new File(cleanupDir)); // cleanupDir was ""
// after
File dir = new File(cleanupDir);
if (cleanupDir == null || cleanupDir.isEmpty() || !dir.isAbsolute() || dir.getParentFile() == null) {
  throw new IllegalArgumentException("Refusing suspicious delete path: " + cleanupDir);
}
IOUtils.deleteRecursively(dir);
Defensive patterns

Strategy: validation

Validate before calling

if (path == null || path.isEmpty() || !dir.isAbsolute() || dir.getParentFile() == null) throw new IllegalArgumentException("Unsafe delete path");

Try / catch

try { IOUtils.deleteRecursively(dir); } catch (IllegalArgumentException e) { if (e.getMessage().contains("_really_ don't think")) { log.severe("Blocked delete of protected path: " + dir); } else throw e; }

Prevention

When it happens

Trigger: Calling IOUtils.deleteRecursively(new File("/")) or any path whose exact string matches an entry in blockListPathsToRemove.

Common situations: Accidentally passing an empty or root-relative path variable that resolved to "/"; cleanup code driven by a misconfigured base directory; unit tests pointing at root by mistake.

Understand the failure class

Background: Path traversal blocked: "path escapes the workspace" and "outside site root" errors when a path will not stay inside its allowed directory — this error's family across 26 libraries.

Related errors


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

Appendix: source

Thrown at src/edu/stanford/nlp/io/IOUtils.java:2027

  }};

  /**
   * Delete this file; or, if it is a directory, delete this directory and all its contents.
   * This is a somewhat dangerous function to call from code, and so a few safety features have been
   * implemented (though you should not rely on these!):
   *
   * <ul>
   *   <li>Certain directories are prohibited from being removed.</li>
   *   <li>More than 100 files cannot be removed with this function.</li>
   *   <li>More than 10GB cannot be removed with this function.</li>
   * </ul>
   *
   * @param file The file or directory to delete.
   */
  public static void deleteRecursively(File file) {
    // Sanity checks
    if (blockListPathsToRemove.contains(file.getPath())) {
      throw new IllegalArgumentException("You're trying to delete " + file + "! I _really_ don't think you want to do that...");
    }
    int count = 0;
    long size = 0;
    for (File f : iterFilesRecursive(file)) {
      count += 1;
      size += f.length();
    }
    if (count > 100) {
      throw new IllegalArgumentException("Deleting more than 100 files; you should do this manually");
    }
    if (size > 10000000000L) {  // 10 GB
      throw new IllegalArgumentException("Deleting more than 10GB; you should do this manually");
    }
    // Do delete
    if (file.isDirectory()) {
      File[] children = file.listFiles();
      if (children != null) {
        for (File child : children) {

View on GitHub (pinned to 1b7edd19c4)