stanfordnlp/CoreNLP · error · IOException

cp: omitting directory

Error message

cp: omitting directory: <source>

What it means

IOUtils.cp(File, File, boolean recursive) throws this IOException when the source is a directory but recursive=false, mirroring cp(1)'s "cp: omitting directory" behavior. Plain (non-recursive) copy only supports files; pass recursive=true to copy directories.

Solutions

  1. Pass recursive=true to IOUtils.cp when the source may be a directory.
  2. Pre-check source.isDirectory() and branch: use cp(..., true) for directories, cp(..., false) for files.
  3. If the directory should never be copied here, validate inputs earlier and produce a clearer error.

Example fix

// before
IOUtils.cp(new File(modelDir), new File(destDir), false);
// after
File src = new File(modelDir);
IOUtils.cp(src, new File(destDir), src.isDirectory());
Defensive patterns

Strategy: validation

Validate before calling

File src = new File(sourcePath);
if (src.isDirectory() && !recursive)
  throw new IllegalArgumentException("Source is a directory; pass recursive=true: " + src);

Try / catch

try {
  IOUtils.cp(src, target, recursive);
} catch (IOException e) {
  if (e.getMessage().startsWith("cp: omitting directory")) {
    IOUtils.cp(src, target, true); // retry with recursion
  } else throw e;
}

Prevention

When it happens

Trigger: Calling IOUtils.cp(source, target, false) — or an overload defaulting to non-recursive — where source.isDirectory() is true.

Common situations: Copying a folder of model/dependency files with the no-recursive flag; a variable that is normally a file sometimes points to a directory; migrating scripts from cp -r semantics without updating the flag.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


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

Appendix: source

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

  }


  /**
   * <p>An implementation of cp, as close to the Unix command as possible.
   * Both directories and files are valid for either the source or the target;
   * if the target exists, the semantics of Unix cp are [intended to be] obeyed.</p>
   *
   * @param source The source file or directory.
   * @param target The target to write this file or directory to.
   * @param recursive If true, recursively copy directory contents
   * @throws IOException If either the copy fails (standard IO Exception), or the command is invalid
   *                     (e.g., copying a directory without the recursive flag)
   */
  public static void cp(File source, File target, boolean recursive) throws IOException {
    // Error checks
    if (source.isDirectory() && !recursive) {
      // cp a b -- a is a directory
      throw new IOException("cp: omitting directory: " + source);
    }
    if (!target.getParentFile().exists()) {
      // cp a b/c/d/e -- b/c/d doesn't exist
      throw new IOException("cp: cannot copy to directory: " + recursive + " (parent doesn't exist)");
    }
    if (!target.getParentFile().isDirectory()) {
      // cp a b/c/d/e -- b/c/d is a regular file
      throw new IOException("cp: cannot copy to directory: " + recursive + " (parent isn't a directory)");
    }
    // Get true target
    File trueTarget;
    if (target.exists() && target.isDirectory()) {
      trueTarget = new File(target.getPath() + File.separator + source.getName());
    } else {
      trueTarget = target;
    }
    // Copy
    if (source.isFile()) {

View on GitHub (pinned to 1b7edd19c4)