{"record":{"id":"8bb71ff248a422b3","repo":"apache/hadoop","slug":"a-directory-with-that-name-exists-s","errorCode":null,"errorMessage":"A directory with that name exists: %s","messagePattern":"A directory with that name exists: (.+?)","errorType":"exception","errorClass":"FileAlreadyExistsException","httpStatus":null,"severity":"error","filePath":"hadoop-cloud-storage-project/hadoop-gcp/src/main/java/org/apache/hadoop/fs/gs/GoogleCloudStorageFileSystem.java","lineNumber":140,"sourceCode":"    //\n    // For example, for a new `gs://bucket/c/d/f` file:\n    // - files `gs://bucket/c` and `gs://bucket/c/d` should not exist\n    // - directory `gs://bucket/c/d/f/` should not exist\n    if (configuration.isEnsureNoConflictingItems()) {\n      // Check if a directory with the same name exists.\n      StorageResourceId dirId = resourceId.toDirectoryId();\n      Boolean conflictingDirExist = false;\n      if (createOptions.isEnsureNoDirectoryConflict()) {\n        // TODO: Do this concurrently\n        conflictingDirExist =\n            getFileInfoInternal(dirId, /* inferImplicitDirectories */ true).exists();\n      }\n\n      checkNoFilesConflictingWithDirs(resourceId);\n\n      // Check if a directory with the same name exists.\n      if (conflictingDirExist) {\n        throw new FileAlreadyExistsException(\"A directory with that name exists: \" + path);\n      }\n    }\n\n    if (createOptions.getOverwriteGenerationId() != StorageResourceId.UNKNOWN_GENERATION_ID) {\n      resourceId = new StorageResourceId(resourceId.getBucketName(), resourceId.getObjectName(),\n          createOptions.getOverwriteGenerationId());\n    }\n\n    return gcs.create(resourceId, createOptions);\n  }\n\n  void close() {\n    if (gcs == null) {\n      return;\n    }\n    LOG.trace(\"close()\");\n    try {\n      gcs.close();","sourceCodeStart":122,"sourceCodeEnd":158,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-cloud-storage-project/hadoop-gcp/src/main/java/org/apache/hadoop/fs/gs/GoogleCloudStorageFileSystem.java#L122-L158","documentation":"create() throws FileAlreadyExistsException when a directory with the target name exists. The check runs when createOptions.isEnsureNoDirectoryConflict() and uses getFileInfoInternal(dirId, inferImplicitDirectories=true), so BOTH an explicit directory-marker object (gs://b/foo/) and an implicit directory (any child gs://b/foo/... exists) count as a conflict. It fires after the file/directory name check and the files-conflicting-with-dirs check.","triggerScenarios":"create(gs://bucket/foo) when gs://bucket/foo/ exists as a directory marker OR any object under the gs://bucket/foo/ prefix exists — e.g. a partition directory already written by a previous job.","commonSituations":"Writing a file where a Hive/Spark partition directory of the same name lives; output collisions between a file writer and directory-creating code; leftover data from failed jobs occupying the name as a prefix.","solutions":["Pick a different file name, or remove/rename the conflicting directory tree before creating the file.","Clean up stale children from previous runs before the job starts.","Only if your semantics tolerate it, disable the conflict check (ensureNoDirectoryConflict=false in CreateFileOptions) — note GCS would then allow a file and a same-named prefix to coexist, which confuses later listings."],"exampleFix":"// before\ngcsFs.create(URI.create(\"gs://b/foo\"), CreateFileOptions.DEFAULT); // FileAlreadyExistsException\n\n// after: clear the conflicting directory first\ngcsFs.delete(URI.create(\"gs://b/foo/\"), /*recursive=*/ true);\ngcsFs.create(URI.create(\"gs://b/foo\"), CreateFileOptions.DEFAULT);","handlingStrategy":"try-catch","validationCode":"// Pre-check: both explicit marker and implicit (children) directories conflict\nFileInfo dirInfo = gcsFs.getFileInfoInternal(\n    resourceId.toDirectoryId(), /* inferImplicitDirectories */ true);\nif (dirInfo.exists()) {\n  throw new OutputNameConflictException(resourceId); // decide: pick new name or clean\n}\ngcsFs.create(path, CreateFileOptions.DEFAULT);","typeGuard":null,"tryCatchPattern":"catch (FileAlreadyExistsException e) {\n  // a directory (explicit marker or implicit via children) owns this name\n  // either choose a new file name or delete/rename the directory tree first\n}","preventionTips":["Keep file names and partition-directory names disjoint by construction (naming scheme/suffixes).","Clean stale job outputs before reruns.","Remember the conflict check sees implicit directories: any child under the prefix blocks the name."],"tags":["gcs","create","file-exists","directory-conflict","implicit-directory"],"backgroundTag":"file-directory-name-conflict","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}