stanfordnlp/CoreNLP · error · IOException

cp: unknown file type

Error message

cp: unknown file type: <source>

What it means

IOUtils.cp only knows how to copy regular files and directories (checked via isDirectory/isFile). If the source is neither — e.g. a broken symlink, special device, socket, fifo, or a file that vanished between listFiles() and the type check — it throws this IOException.

Solutions

  1. Validate the source before copying: source.exists() && (source.isFile() || source.isDirectory())
  2. Resolve or remove broken symlinks to a real file/directory
  3. Only pass regular files and directories to cp

Example fix

// before
IOUtils.cp(new File("link-to-nowhere"), target, true); // broken symlink
// after
File src = new File("link-to-nowhere").getCanonicalFile();
if (!src.exists() || !(src.isFile() || src.isDirectory())) {
  throw new IllegalArgumentException("Not a regular file or directory: " + src);
}
IOUtils.cp(src, target, true);
Defensive patterns

Strategy: validation

Validate before calling

if (!src.exists() || !(src.isFile() || src.isDirectory())) throw new IllegalArgumentException("Bad cp source: " + src);

Try / catch

try { IOUtils.cp(src, target, recursive); } catch (IOException e) { if (e.getMessage().startsWith("cp: unknown file type")) { /* resolve symlink / skip special file */ } else throw e; }

Prevention

When it happens

Trigger: Calling IOUtils.cp with a source File that is not a normal file/directory: broken symlink, /dev node, fifo, or a deleted-in-flight path; also recursive cp encountering such a child.

Common situations: Copying from symlinked paths where the link is dangling; copying special files on Unix; TOCTOU where the source disappears mid-copy.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


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

Appendix: source

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

        if (!trueTarget.exists() && !trueTarget.mkdir()) {
          // cp -r a b -- b/a cannot be created
          throw new IOException("cp: could not create directory: " + trueTarget);
        }
      } else {
        // Case: cp -r a b -- b does not exist
        assert trueTarget == target;
        if (!trueTarget.mkdir()) {
          // cp -r a b -- cannot create b as a directory
          throw new IOException("cp: could not create target directory: " + trueTarget);
        }
      }
      // Actually do the copy
      for (File child : children) {
        File childTarget = new File(trueTarget.getPath() + File.separator + child.getName());
        cp(child, childTarget, recursive);
      }
    } else {
      throw new IOException("cp: unknown file type: " + source);
    }
  }

  /**
   * @see IOUtils#cp(java.io.File, java.io.File, boolean)
   */
  public static void cp(File source, File target) throws IOException { cp(source, target, false); }

  /**
   * A Java implementation of the Unix tail functionality.
   * That is, read the last n lines of the input file f.
   * @param f The file to read the last n lines from
   * @param n The number of lines to read from the end of the file.
   * @param encoding The encoding to read the file in.
   * @return The read lines, one String per line.
   * @throws IOException if the file could not be read.
   */
  public static String[] tail(File f, int n, String encoding) throws IOException {

View on GitHub (pinned to 1b7edd19c4)