{"record":{"id":"ce40d84c6aa01029","repo":"apache/hadoop","slug":"cannot-copy-to-its-subdirectory","errorCode":null,"errorMessage":"Cannot copy {} to its subdirectory {}","messagePattern":"Cannot copy (.+?) to its subdirectory (.+?)","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileUtil.java","lineNumber":348,"sourceCode":"  }\n\n  //\n  // If the destination is a subdirectory of the source, then\n  // generate exception\n  //\n  private static void checkDependencies(FileSystem srcFS,\n                                        Path src,\n                                        FileSystem dstFS,\n                                        Path dst)\n                                        throws IOException {\n    if (srcFS == dstFS) {\n      String srcq = srcFS.makeQualified(src).toString() + Path.SEPARATOR;\n      String dstq = dstFS.makeQualified(dst).toString() + Path.SEPARATOR;\n      if (dstq.startsWith(srcq)) {\n        if (srcq.length() == dstq.length()) {\n          throw new IOException(\"Cannot copy \" + src + \" to itself.\");\n        } else {\n          throw new IOException(\"Cannot copy \" + src + \" to its subdirectory \" +\n                                dst);\n        }\n      }\n    }\n  }\n\n  /**\n   * Copy files between FileSystems.\n   * @param srcFS src fs.\n   * @param src src.\n   * @param dstFS dst fs.\n   * @param dst dst.\n   * @param deleteSource delete source.\n   * @param conf configuration.\n   * @return if copy success true, not false.\n   * @throws IOException raised on errors performing I/O.\n   */\n  public static boolean copy(FileSystem srcFS, Path src,","sourceCodeStart":330,"sourceCodeEnd":366,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileUtil.java#L330-L366","documentation":"Error \"Cannot copy {} to its subdirectory {}\" thrown in apache/hadoop.","triggerScenarios":"Thrown at hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileUtil.java:348 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Pick a destination outside the source directory tree.","Copy the source elsewhere first if the intent is a nested duplicate."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}