apache/hadoop · error · IOException
Cannot copy {} to its subdirectory {}
Error message
Cannot copy {} to its subdirectory {} What it means
Error "Cannot copy {} to its subdirectory {}" thrown in apache/hadoop.
Source
Thrown at hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileUtil.java:348
}
//
// If the destination is a subdirectory of the source, then
// generate exception
//
private static void checkDependencies(FileSystem srcFS,
Path src,
FileSystem dstFS,
Path dst)
throws IOException {
if (srcFS == dstFS) {
String srcq = srcFS.makeQualified(src).toString() + Path.SEPARATOR;
String dstq = dstFS.makeQualified(dst).toString() + Path.SEPARATOR;
if (dstq.startsWith(srcq)) {
if (srcq.length() == dstq.length()) {
throw new IOException("Cannot copy " + src + " to itself.");
} else {
throw new IOException("Cannot copy " + src + " to its subdirectory " +
dst);
}
}
}
}
/**
* Copy files between FileSystems.
* @param srcFS src fs.
* @param src src.
* @param dstFS dst fs.
* @param dst dst.
* @param deleteSource delete source.
* @param conf configuration.
* @return if copy success true, not false.
* @throws IOException raised on errors performing I/O.
*/
public static boolean copy(FileSystem srcFS, Path src,View on GitHub (pinned to 2add963021)
Solutions
- Pick a destination outside the source directory tree.
- Copy the source elsewhere first if the intent is a nested duplicate.
When it happens
Trigger: Thrown at hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileUtil.java:348 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22).
Data as JSON: /api/errors/ce40d84c6aa01029.
Report an issue: GitHub.