apache/hadoop · error · PathIsDirectoryException
Is a directory
Error message
Is a directory
What it means
PathIsDirectoryException (message 'Is a directory') thrown by Getmerge.processOptions (CopyCommands.java:83) for the 'hadoop fs -getmerge' command. The destination argument (the last argument) already exists and is a directory. getmerge merges many source files into ONE local output file, so the destination must be a (typically nonexistent) file path, not a directory.
Source
Thrown at hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/CopyCommands.java:83
protected PathData dst = null;
protected String delimiter = null;
private boolean skipEmptyFileDelimiter;
protected List<PathData> srcs = null;
@Override
protected void processOptions(LinkedList<String> args) throws IOException {
try {
CommandFormat cf = new CommandFormat(2, Integer.MAX_VALUE, "nl",
"skip-empty-file");
cf.parse(args);
delimiter = cf.getOpt("nl") ? "\n" : null;
skipEmptyFileDelimiter = cf.getOpt("skip-empty-file");
dst = new PathData(new URI(args.removeLast()), getConf());
if (dst.exists && dst.stat.isDirectory()) {
throw new PathIsDirectoryException(dst.toString());
}
srcs = new LinkedList<PathData>();
} catch (URISyntaxException e) {
throw new IOException("unexpected URISyntaxException", e);
}
}
@Override
protected void processArguments(LinkedList<PathData> items)
throws IOException {
super.processArguments(items);
if (exitCode != 0) { // check for error collecting paths
return;
}
FSDataOutputStream out = dst.fs.create(dst.path);
try {
for (PathData src : srcs) {
if (src.stat.getLen() != 0) {View on GitHub (pinned to 2add963021)
Solutions
- Point the destination at a file name that does not exist: 'hadoop fs -getmerge /hdfs/src/dir /local/merged.txt'
- Or keep the directory and append a file name to it: 'hadoop fs -getmerge /hdfs/src/dir /local/output/merged.txt'
- If the directory was created by mistake in a prior step, remove or skip that mkdir
- Use the -nl option only after the destination is a valid file path (options are unrelated but often appear in the same failing scripts)
Example fix
# before mkdir -p /local/out hadoop fs -getmerge /src/dir /local/out # Is a directory # after mkdir -p /local/out hadoop fs -getmerge /src/dir /local/out/merged.txt
Defensive patterns
Strategy: validation
Validate before calling
PathData dst = new PathData(new URI(dstArg), getConf());
if (dst.exists && dst.stat.isDirectory()) {
throw new PathIsDirectoryException(dst.toString());
} Type guard
static boolean isValidGetmergeDestination(PathData dst) throws IOException {
return !(dst.exists && dst.stat.isDirectory());
} Try / catch
try {
// run getmerge
} catch (PathIsDirectoryException e) {
// append an output file name to the directory and retry
} Prevention
- Always pass a full output FILE path to getmerge, never a directory
- In scripts, derive the destination as "$DIR/merged.txt"
- Never mkdir the getmerge destination beforehand
When it happens
Trigger: 'hadoop fs -getmerge /hdfs/src/dir /local/output' where /local/output is an existing directory; scripts that pass a target directory expecting cp/mv-like semantics; a destination created beforehand with mkdir by the same script.
Common situations: Copy/paste of a 'cp -r' idiom where the last arg is a directory; automation that derives the destination from a directory variable; users expecting getmerge to write merged.txt into the given folder automatically.
Related errors
- Is a directory
- Is a directory
- Is a directory
- Illegal option {}
- Not enough arguments: expected {} but got {}
AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22).
Data as JSON: /api/errors/dabbc1733fe99495.
Report an issue: GitHub.