{"record":{"id":"2b6749447a772f2b","repo":"stanfordnlp/CoreNLP","slug":"cp-unknown-file-type-source","errorCode":null,"errorMessage":"cp: unknown file type: <source>","messagePattern":"cp: unknown file type: <source>","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/io/IOUtils.java","lineNumber":1930,"sourceCode":"        if (!trueTarget.exists() && !trueTarget.mkdir()) {\n          // cp -r a b -- b/a cannot be created\n          throw new IOException(\"cp: could not create directory: \" + trueTarget);\n        }\n      } else {\n        // Case: cp -r a b -- b does not exist\n        assert trueTarget == target;\n        if (!trueTarget.mkdir()) {\n          // cp -r a b -- cannot create b as a directory\n          throw new IOException(\"cp: could not create target directory: \" + trueTarget);\n        }\n      }\n      // Actually do the copy\n      for (File child : children) {\n        File childTarget = new File(trueTarget.getPath() + File.separator + child.getName());\n        cp(child, childTarget, recursive);\n      }\n    } else {\n      throw new IOException(\"cp: unknown file type: \" + source);\n    }\n  }\n\n  /**\n   * @see IOUtils#cp(java.io.File, java.io.File, boolean)\n   */\n  public static void cp(File source, File target) throws IOException { cp(source, target, false); }\n\n  /**\n   * A Java implementation of the Unix tail functionality.\n   * That is, read the last n lines of the input file f.\n   * @param f The file to read the last n lines from\n   * @param n The number of lines to read from the end of the file.\n   * @param encoding The encoding to read the file in.\n   * @return The read lines, one String per line.\n   * @throws IOException if the file could not be read.\n   */\n  public static String[] tail(File f, int n, String encoding) throws IOException {","sourceCodeStart":1912,"sourceCodeEnd":1948,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/io/IOUtils.java#L1912-L1948","documentation":"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.","triggerScenarios":"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.","commonSituations":"Copying from symlinked paths where the link is dangling; copying special files on Unix; TOCTOU where the source disappears mid-copy.","solutions":["Validate the source before copying: source.exists() && (source.isFile() || source.isDirectory())","Resolve or remove broken symlinks to a real file/directory","Only pass regular files and directories to cp"],"exampleFix":"// before\nIOUtils.cp(new File(\"link-to-nowhere\"), target, true); // broken symlink\n// after\nFile src = new File(\"link-to-nowhere\").getCanonicalFile();\nif (!src.exists() || !(src.isFile() || src.isDirectory())) {\n  throw new IllegalArgumentException(\"Not a regular file or directory: \" + src);\n}\nIOUtils.cp(src, target, true);","handlingStrategy":"validation","validationCode":"if (!src.exists() || !(src.isFile() || src.isDirectory())) throw new IllegalArgumentException(\"Bad cp source: \" + src);","typeGuard":null,"tryCatchPattern":"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; }","preventionTips":["Canonicalize symlinks with getCanonicalFile() first","Skip special files (sockets, fifos) when walking trees","Check exists() before copying to avoid TOCTOU races"],"tags":["io","filesystem","unsupported-file-type"],"backgroundTag":"unsupported-operation","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}