{"record":{"id":"499d39e28653d038","repo":"stanfordnlp/CoreNLP","slug":"cp-could-not-create-target-directory-truetarget","errorCode":null,"errorMessage":"cp: could not create target directory: <trueTarget>","messagePattern":"cp: could not create target directory: <trueTarget>","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/io/IOUtils.java","lineNumber":1921,"sourceCode":"        // Case: cp -r a b -- b exists\n        if (!target.isDirectory()) {\n          // cp -r a b -- b is a regular file\n          throw new IOException(\"cp: cannot copy directory into regular file: \" + target);\n        }\n        if (trueTarget.exists() && !trueTarget.isDirectory()) {\n          // cp -r a b -- b/a is not a directory\n          throw new IOException(\"cp: overwriting a file with a directory: \" + trueTarget);\n        }\n        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  /**","sourceCodeStart":1903,"sourceCodeEnd":1939,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/io/IOUtils.java#L1903-L1939","documentation":"When the cp target does not exist, the method tries to create it as a directory with trueTarget.mkdir(); if that fails it throws this IOException. Unlike the parented case, the created directory here IS the target itself.","triggerScenarios":"IOUtils.cp(dirA, nonExistentPathB, true) where nonExistentPathB.mkdir() returns false — typically because B's parent directory does not exist (mkdir does not create parents), or lacks write permission.","commonSituations":"Target path has missing intermediate directories (users expect mkdir -p behavior but this is plain mkdir); wrong absolute path; read-only parent directory.","solutions":["Create the parent directories first with target.getParentFile().mkdirs() before calling cp","Use mkdirs() semantics yourself: new File(path).mkdirs() then cp","Verify the target's parent directory exists and is writable"],"exampleFix":"// before\nIOUtils.cp(src, new File(\"out/a/b\"), true); // out/a missing\n// after\nFile target = new File(\"out/a/b\");\ntarget.mkdirs();\nIOUtils.cp(src, target, true);","handlingStrategy":"validation","validationCode":"File parent = target.getParentFile(); if (parent != null) parent.mkdirs();","typeGuard":null,"tryCatchPattern":"try { IOUtils.cp(src, target, true); } catch (IOException e) { if (e.getMessage().startsWith(\"cp: could not create target directory\")) { target.getParentFile().mkdirs(); IOUtils.cp(src, target, true); } else throw e; }","preventionTips":["Always call target.mkdirs() (not mkdir) before copying to a new path","Validate absolute target paths in config","Check parent dir write permission"],"tags":["io","filesystem","mkdir","missing-parent-directory"],"backgroundTag":"mkdir-permission-denied","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}