apache/hadoop · error · FileNotFoundException
No such file or directory: {}
Error message
No such file or directory: {} What it means
renameFile sends the OBS POSIX RenameRequest; an ObsException with response code 404 means the source key does not exist, and it is surfaced as FileNotFoundException('No such file or directory: <srcKey>'). Note the message carries the object key, not the Path.
Source
Thrown at hadoop-cloud-storage-project/hadoop-huaweicloud/src/main/java/org/apache/hadoop/fs/obs/OBSPosixBucketUtils.java:278
"renameFile(" + src + ", " + dst + ")", src, e);
}
}
static void innerFsRenameFile(final OBSFileSystem owner,
final String srcKey,
final String dstKey) throws IOException {
LOG.debug("RenameFile path {} to {}", srcKey, dstKey);
try {
final RenameRequest renameObjectRequest = new RenameRequest();
renameObjectRequest.setBucketName(owner.getBucket());
renameObjectRequest.setObjectKey(srcKey);
renameObjectRequest.setNewObjectKey(dstKey);
owner.getObsClient().renameFile(renameObjectRequest);
owner.getSchemeStatistics().incrementWriteOps(1);
} catch (ObsException e) {
if (e.getResponseCode() == OBSCommonUtils.NOT_FOUND_CODE) {
throw new FileNotFoundException(
"No such file or directory: " + srcKey);
}
if (e.getResponseCode() == OBSCommonUtils.CONFLICT_CODE) {
throw new FileConflictException(
"File conflicts during rename, " + e.getResponseStatus());
}
throw OBSCommonUtils.translateException(
"renameFile(" + srcKey + ", " + dstKey + ")", srcKey, e);
}
}
/**
* Used to rename a source object to a destination object which is not existed
* before rename.
*
* @param owner OBS File System instance
* @param srcKey source object key
* @param dstKey destination object keyView on GitHub (pinned to 2add963021)
Solutions
- Treat FileNotFoundException on rename as 'already moved' when the destination exists: verify with getFileStatus(dst) and report success
- Guard with an existence check immediately before the rename where races are possible
- Log the failing key and compare it against a listing of the parent prefix to catch path-construction bugs
Example fix
// before
fs.rename(src, dst);
// after
try {
fs.rename(src, dst);
} catch (FileNotFoundException e) {
if (!fs.exists(dst)) {
throw e; // genuinely missing source
}
// moved by a concurrent attempt: treat as success
} Defensive patterns
Strategy: try-catch
Validate before calling
if (!fs.exists(src)) {
if (fs.exists(dst)) {
// already moved by a concurrent attempt: treat as success
} else {
throw new FileNotFoundException("Missing source: " + src);
}
} Try / catch
try {
fs.rename(src, dst);
} catch (FileNotFoundException e) {
if (fs.exists(dst)) {
// source already moved: idempotent success
} else {
throw e; // genuinely missing source
}
} Prevention
- Treat FNFE on rename as a possible concurrent move, not only as corruption
- Verify both endpoints when tasks may be speculative or retried
- Log object keys on failure so races can be distinguished from path bugs
When it happens
Trigger: Renaming an object already moved or deleted by another client or task attempt; a source path typo or an unqualified path that resolved to a different key; the visibility window after a concurrent create.
Common situations: Idempotent job retry where the first attempt already moved the source; concurrent tasks racing on the same input; speculative executions of the same task.
Understand the failure class
Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.
Related errors
- {} is not a directory
- File conflicts during rename, {}
- {} is root directory
- new destination is an existed directory
- new destination is an existed file
AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22).
Data as JSON: /api/errors/ed245de168fc965e.
Report an issue: GitHub.