apache/hadoop · error · FileAlreadyExistsException
f + " is a directory"
Error message
f + " is a directory"
What it means
The new-mapreduce-API StreamInputFormat (org.apache.hadoop.streaming.mapreduce) reads stream.recordreader.class and resolves it with StreamUtil.goodClassOrNull(conf, c, null) — note the null defaultPackage, so no package prefix is ever appended. If the class cannot be loaded by name it throws RuntimeException 'Class not found'. This guards the factory dispatch that instantiates non-standard record readers such as the mapreduce StreamXmlRecordReader.
Source
Thrown at hadoop-cloud-storage-project/hadoop-bos/src/main/java/org/apache/hadoop/fs/bos/BaiduBosFileSystem.java:189
FileStatus result = stats[i++];
BlockLocation[] locs = result.isFile()
? getFileBlockLocations(result, 0, result.getLen())
: null;
return new LocatedFileStatus(result, locs);
}
};
}
@Override
public FSDataOutputStream create(Path f, FsPermission permission,
boolean overwrite, int bufferSize, short replication,
long blockSize, Progressable progress) throws IOException {
Path absolutePath = makeAbsolute(f);
String key = pathToKey(absolutePath);
if (overwrite) {
if (store.isDirectory(key)) {
throw new FileAlreadyExistsException(
f + " is a directory");
}
} else {
try {
getFileStatus(f);
throw new FileAlreadyExistsException(
f + " already exists");
} catch (FileNotFoundException e) {
// nothing, ok
}
}
return new FSDataOutputStream(
store.createFile(key, getConf()), statistics);
}
/**
* Create a file non-recursively. The parent directory mustView on GitHub (pinned to 2add963021)
Solutions
- Use the fully-qualified name: -inputreader org.apache.hadoop.streaming.mapreduce.StreamXmlRecordReader (short names do not work here because no default package is applied).
- Fix typos/dotted-path mistakes in the stream.recordreader.class value; verify the class exists with `hadoop classpath` + javap or a local Class.forName test.
- If the reader is your own, ship its jar with -libjars (or package it inside the job jar) so the task classloader can find it.
- For standard line-based input, remove -inputreader entirely; StreamInputFormat delegates to KeyValueTextInputFormat when the class name contains 'LineRecordReader' or is unset.
Example fix
# before -inputreader StreamXmlRecordReader # unqualified -> 'Class not found: StreamXmlRecordReader' # after -inputreader org.apache.hadoop.streaming.mapreduce.StreamXmlRecordReader
Defensive patterns
Strategy: validation
Validate before calling
String c = conf.get("stream.recordreader.class");
if (c != null && StreamUtil.goodClassOrNull(conf, c, null) == null) {
throw new IllegalArgumentException(
"stream.recordreader.class not loadable (use FQCN, add jar to classpath): " + c);
} Prevention
- Always use the fully-qualified class name with -inputreader on the mapreduce path (no default package is applied).
- Ship custom reader jars with -libjars.
- Smoke-test Class.forName on the task classpath before submitting.
When it happens
Trigger: Setting stream.recordreader.class (via -inputreader ...) to a class missing from the task classpath, or to a bare short name like 'StreamXmlRecordReader' — because defaultPackage is null, the unqualified name is never resolved to org.apache.hadoop.streaming.mapreduce.StreamXmlRecordReader.
Common situations: Streaming jobs using the mapreduce API path with -inputreader; typos in the fully-qualified class name; custom record reader jar not shipped with -libjars so ClassNotFoundException is swallowed by goodClassOrNull and resurfaces as this RuntimeException.
Related errors
- No more entry in " + f
- f + " already exists"
- Could not find configured fencing method {}
- Path must be absolute: " + path
- Append is not supported by BaiduBosFileSystem
AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22).
Data as JSON: /api/errors/1b9383c5376db917.
Report an issue: GitHub.