apache/hadoop · error · FileNotFoundException
Cannot create file {} because parent folder does not exist.
Error message
Cannot create file {} because parent folder does not exist. What it means
Before creating a file on a non-HNS (flat-namespace/blob endpoint) account, AbfsBlobClient validates the parent with GetPathStatus; a 404 is translated into java.io.FileNotFoundException('Cannot create file <parent> because parent folder does not exist.'), preserving the Hadoop FileSystem contract that create() fails when the parent directory is missing. On blob endpoints directories are marker blobs, so a missing marker means a missing directory.
Source
Thrown at hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/AbfsBlobClient.java:469
/**{@inheritDoc}*/
@Override
public void createNonRecursivePreCheck(Path parentPath,
TracingContext tracingContext)
throws IOException {
try {
if (isAtomicRenameKey(parentPath.toUri().getPath())) {
takeGetPathStatusAtomicRenameKeyAction(parentPath, tracingContext);
}
try {
getPathStatus(parentPath.toUri().getPath(), false,
tracingContext, null);
} finally {
getAbfsCounters().incrementCounter(CALL_GET_FILE_STATUS, 1);
}
} catch (AbfsRestOperationException ex) {
if (ex.getStatusCode() == HttpURLConnection.HTTP_NOT_FOUND) {
throw new FileNotFoundException("Cannot create file "
+ parentPath.toUri().getPath()
+ " because parent folder does not exist.");
}
throw ex;
}
}
/**
* Get Rest Operation for API
* <a href="../../../../site/markdown/blobEndpoint.md#put-blob">Put Blob</a>.
* Creates a file or directory (marker file) at the specified path.
*
* @param path the path of the directory to be created.
* @param isFileCreation whether the path to create is a file.
* @param overwrite whether to overwrite if the path already exists.
* @param permissions the permissions to set on the path.
* @param isAppendBlob whether the path is an append blob.
* @param eTag the eTag of the path.View on GitHub (pinned to 2add963021)
Solutions
- Create the parent first: fs.mkdirs(path.getParent()) before fs.create(path)
- Ensure no concurrent job deletes the parent directory during the write phase
- Read the exact missing parent from the exception message — it names the specific directory that is absent
- Use an HNS-enabled account for native directory semantics if this pattern is frequent
Example fix
// before: parent marker missing -> FileNotFoundException
try (FSDataOutputStream out = fs.create(new Path("abfs://c@acct.dfs.core.windows.net/dir/sub/f"))) { ... }
// after: materialize the parent hierarchy first
Path file = new Path("abfs://c@acct.dfs.core.windows.net/dir/sub/f");
fs.mkdirs(file.getParent());
try (FSDataOutputStream out = fs.create(file)) { ... } Defensive patterns
Strategy: validation
Validate before calling
Path parent = path.getParent();
if (parent != null && !fs.exists(parent)) {
fs.mkdirs(parent); // materialize marker hierarchy on blob endpoints
}
try (FSDataOutputStream out = fs.create(path)) { ... } Try / catch
try {
fs.create(path);
} catch (FileNotFoundException e) {
// message names the missing parent; mkdirs and retry once
fs.mkdirs(path.getParent());
fs.create(path);
} Prevention
- Always mkdirs the parent on non-HNS accounts before creating deep paths
- Prevent concurrent cleanup jobs from deleting directories that writers depend on
- Remember blob endpoints do not auto-create parents unlike object stores
When it happens
Trigger: fs.create(path) against an abfs:// account without hierarchical namespace where the parent directory has no marker blob: never created, previously deleted, or marker creation skipped/raced.
Common situations: Writing deep paths without mkdirs on non-HNS accounts; a cleanup job deleting the parent directory while writers run; code assuming blob-storage auto-creates parents like AWS S3 does.
Related errors
- PathConflict
- Parallel access to the create path detected. Failing request
- FNS-Blob rename was not successful for source and destinatio
- FNS-Blob delete was not successful for path: {}
- Can not create '%s' file, because parent folder does not exi
AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22).
Data as JSON: /api/errors/199f01d1724d2a49.
Report an issue: GitHub.