{"record":{"id":"199f01d1724d2a49","repo":"apache/hadoop","slug":"cannot-create-file-because-parent-folder-does-n","errorCode":null,"errorMessage":"Cannot create file {} because parent folder does not exist.","messagePattern":"Cannot create file (.+?) because parent folder does not exist\\.","errorType":"exception","errorClass":"FileNotFoundException","httpStatus":null,"severity":"error","filePath":"hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/AbfsBlobClient.java","lineNumber":469,"sourceCode":"\n  /**{@inheritDoc}*/\n  @Override\n  public void createNonRecursivePreCheck(Path parentPath,\n      TracingContext tracingContext)\n      throws IOException {\n    try {\n      if (isAtomicRenameKey(parentPath.toUri().getPath())) {\n        takeGetPathStatusAtomicRenameKeyAction(parentPath, tracingContext);\n      }\n      try {\n        getPathStatus(parentPath.toUri().getPath(), false,\n            tracingContext, null);\n      } finally {\n        getAbfsCounters().incrementCounter(CALL_GET_FILE_STATUS, 1);\n      }\n    } catch (AbfsRestOperationException ex) {\n      if (ex.getStatusCode() == HttpURLConnection.HTTP_NOT_FOUND) {\n        throw new FileNotFoundException(\"Cannot create file \"\n            + parentPath.toUri().getPath()\n            + \" because parent folder does not exist.\");\n      }\n      throw ex;\n    }\n  }\n\n  /**\n   * Get Rest Operation for API\n   * <a href=\"../../../../site/markdown/blobEndpoint.md#put-blob\">Put Blob</a>.\n   * Creates a file or directory (marker file) at the specified path.\n   *\n   * @param path the path of the directory to be created.\n   * @param isFileCreation whether the path to create is a file.\n   * @param overwrite whether to overwrite if the path already exists.\n   * @param permissions the permissions to set on the path.\n   * @param isAppendBlob whether the path is an append blob.\n   * @param eTag the eTag of the path.","sourceCodeStart":451,"sourceCodeEnd":487,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/AbfsBlobClient.java#L451-L487","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before: parent marker missing -> FileNotFoundException\ntry (FSDataOutputStream out = fs.create(new Path(\"abfs://c@acct.dfs.core.windows.net/dir/sub/f\"))) { ... }\n\n// after: materialize the parent hierarchy first\nPath file = new Path(\"abfs://c@acct.dfs.core.windows.net/dir/sub/f\");\nfs.mkdirs(file.getParent());\ntry (FSDataOutputStream out = fs.create(file)) { ... }","handlingStrategy":"validation","validationCode":"Path parent = path.getParent();\nif (parent != null && !fs.exists(parent)) {\n  fs.mkdirs(parent); // materialize marker hierarchy on blob endpoints\n}\ntry (FSDataOutputStream out = fs.create(path)) { ... }","typeGuard":null,"tryCatchPattern":"try {\n  fs.create(path);\n} catch (FileNotFoundException e) {\n  // message names the missing parent; mkdirs and retry once\n  fs.mkdirs(path.getParent());\n  fs.create(path);\n}","preventionTips":["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"],"tags":["azure","abfs","blob-endpoint","create","file-not-found","hadoop"],"backgroundTag":"parent-directory-missing","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}