apache/hadoop · error · FileNotFoundException
Missing parent:${f}
Error message
Missing parent:${f} What it means
primitiveMkdir(f, permission, createParent=false) is the deprecated helper behind non-recursive creates. When createParent is false it stats f.getParent() first; implementations whose getFileStatus returns null for absent paths (instead of throwing) reach the explicit FileNotFoundException('Missing parent: f'). It is the 'parent must already exist' contract made loud.
Source
Thrown at hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileSystem.java:1402
* This a temporary method added to support the transition from FileSystem
* to FileContext for user applications.
*
* @param f the path.
* @param absolutePermission permission.
* @param createParent create parent.
* @throws IOException IO failure.
*/
@Deprecated
protected void primitiveMkdir(Path f, FsPermission absolutePermission,
boolean createParent)
throws IOException {
if (!createParent) { // parent must exist.
// since the this.mkdirs makes parent dirs automatically
// we must throw exception if parent does not exist.
final FileStatus stat = getFileStatus(f.getParent());
if (stat == null) {
throw new FileNotFoundException("Missing parent:" + f);
}
if (!stat.isDirectory()) {
throw new ParentNotDirectoryException("parent is not a dir");
}
// parent does exist - go ahead with mkdir of leaf
}
// Default impl is to assume that permissions do not matter and hence
// calling the regular mkdirs is good enough.
// FSs that implement permissions should override this.
if (!this.mkdirs(f, absolutePermission)) {
throw new IOException("mkdir of "+ f + " failed");
}
}
/**
* Opens an FSDataOutputStream at the indicated Path with write-progress
* reporting. Same as create(), except fails if parent directory doesn't
* already exist.View on GitHub (pinned to 2add963021)
Solutions
- Create the parent chain first: fs.mkdirs(f.getParent())
- Or use fs.mkdirs(f) / pass createParent=true so parents are created automatically
- If you implement a FileSystem, keep getFileStatus/primitiveMkdir semantics consistent (throw rather than return null)
Example fix
// before fs.primitiveMkdir(dst, FsPermission.getDefault(), false); // parent may be absent // after fs.mkdirs(dst.getParent()); fs.primitiveMkdir(dst, FsPermission.getDefault(), false);
Defensive patterns
Strategy: validation
Validate before calling
Path parent = f.getParent();
if (!fs.exists(parent)) {
fs.mkdirs(parent);
}
fs.primitiveMkdir(f, perm, false); Prevention
- Prefer fs.mkdirs(f) in application code
- Create parent trees as an explicit pipeline step before non-recursive creates
- Re-check parent existence right before the call in racy environments
When it happens
Trigger: Calling primitiveMkdir with createParent=false (including the deprecated 2-arg overload that forwards false) on a path whose parent directory chain does not exist.
Common situations: Non-recursive create flows that assume an earlier step already made the parent; a concurrent job deleting the parent between an exists() check and the mkdir; custom FileSystems that return null from getFileStatus for missing paths.
Related errors
- Parent directory doesn't exist: {}
- Mkdirs failed to create {} (exists={}, cwd={})
- parent is not a dir
- mkdir of ${f} failed
- rename destination parent ${parent} not found.
AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22).
Data as JSON: /api/errors/11cbfa4bfff9ae38.
Report an issue: GitHub.