{"record":{"id":"c4cec18b977e0558","repo":"apache/hadoop","slug":"can-t-make-directory-for-path-s-since-it-is-a-f-c4cec1","errorCode":null,"errorMessage":"Can't make directory for path '%s' since it is a file.","messagePattern":"Can't make directory for path '(.+?)' since it is a file\\.","errorType":"exception","errorClass":"FileAlreadyExistsException","httpStatus":null,"severity":"error","filePath":"hadoop-cloud-storage-project/hadoop-cos/src/main/java/org/apache/hadoop/fs/cosn/CosNFileSystem.java","lineNumber":569,"sourceCode":"        }\n      } catch (FileNotFoundException e) {\n        LOG.debug(\"Making dir: [{}] in COS\", f);\n\n        String folderPath = pathToKey(makeAbsolute(f));\n        if (!folderPath.endsWith(PATH_DELIMITER)) {\n          folderPath += PATH_DELIMITER;\n        }\n        store.storeEmptyFile(folderPath);\n      }\n    }\n    return true;\n  }\n\n  private boolean mkdir(Path f) throws IOException {\n    try {\n      FileStatus fileStatus = getFileStatus(f);\n      if (fileStatus.isFile()) {\n        throw new FileAlreadyExistsException(\n            String.format(\n                \"Can't make directory for path '%s' since it is a file.\", f));\n      }\n    } catch (FileNotFoundException e) {\n      if (LOG.isDebugEnabled()) {\n        LOG.debug(\"Make directory: [{}] in COS.\", f);\n      }\n\n      String folderPath = pathToKey(makeAbsolute(f));\n      if (!folderPath.endsWith(PATH_DELIMITER)) {\n        folderPath += PATH_DELIMITER;\n      }\n      store.storeEmptyFile(folderPath);\n    }\n    return true;\n  }\n\n  @Override","sourceCodeStart":551,"sourceCodeEnd":587,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-cloud-storage-project/hadoop-cos/src/main/java/org/apache/hadoop/fs/cosn/CosNFileSystem.java#L551-L587","documentation":"The single-level mkdir(f) helper throws FileAlreadyExistsException when f already exists as a file. If f exists as a directory the call succeeds; if f is missing it writes a 0-byte 'directory marker' object (key suffixed with '/') into COS. This marker mechanism is exactly why a stray file at a directory key later blocks mkdirs as 'it is a file'.","triggerScenarios":"mkdir on a path occupied by an existing file object; creating a directory whose key equals an existing object key (no trailing slash).","commonSituations":"Layout migrations where a file key is promoted to a directory key; tools that assume mkdir on an existing key is always a no-op.","solutions":["Delete or rename the file occupying the path, then retry mkdir.","Pick a different directory name that cannot collide with existing object keys.","Check getFileStatus(f).isFile() before calling mkdir in shared utilities."],"exampleFix":"// before\nif (!fs.exists(dirPath)) { fs.mkdirs(dirPath); } // still throws if dirPath is a FILE\n\n// after\nif (!fs.exists(dirPath)) {\n  fs.mkdirs(dirPath);\n} else if (fs.getFileStatus(dirPath).isFile()) {\n  fs.delete(dirPath, false);\n  fs.mkdirs(dirPath);\n}","handlingStrategy":"validation","validationCode":"if (fs.exists(f) && fs.getFileStatus(f).isFile()) {\n  // mkdir would throw: delete, rename, or fail fast here\n  throw new IllegalStateException('Path occupied by a file: ' + f);\n}","typeGuard":null,"tryCatchPattern":"try {\n  fs.mkdirs(f);\n} catch (FileAlreadyExistsException e) {\n  if (fs.getFileStatus(f).isFile()) { fs.delete(f, false); fs.mkdirs(f); } else { throw e; }\n}","preventionTips":["Remember CosN directories are 0-byte marker objects; a file at the same key blocks mkdir","Check status type before any create-directory call in shared utilities","Avoid layouts where a key switches between file and directory roles"],"tags":["cosn","hadoop","mkdir","path-is-file","file-already-exists"],"backgroundTag":"mkdir-target-is-file","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}