{"record":{"id":"4523144413cfea20","repo":"apache/hadoop","slug":"not-a-directory-parent","errorCode":null,"errorMessage":"Not a directory: {parent}","messagePattern":"Not a directory: (.+?)","errorType":"exception","errorClass":"FileAlreadyExistsException","httpStatus":null,"severity":"error","filePath":"hadoop-tools/hadoop-aliyun/src/main/java/org/apache/hadoop/fs/aliyun/oss/AliyunOSSFileSystem.java","lineNumber":167,"sourceCode":"\n  /**\n   * {@inheritDoc}\n   * @throws FileNotFoundException if the parent directory is not present -or\n   * is not a directory.\n   */\n  @Override\n  public FSDataOutputStream createNonRecursive(Path path,\n      FsPermission permission,\n      EnumSet<CreateFlag> flags,\n      int bufferSize,\n      short replication,\n      long blockSize,\n      Progressable progress) throws IOException {\n    Path parent = path.getParent();\n    if (parent != null) {\n      // expect this to raise an exception if there is no parent\n      if (!getFileStatus(parent).isDirectory()) {\n        throw new FileAlreadyExistsException(\"Not a directory: \" + parent);\n      }\n    }\n    return create(path, permission, flags.contains(CreateFlag.OVERWRITE),\n        bufferSize, replication, blockSize, progress);\n  }\n\n  @Override\n  public boolean delete(Path path, boolean recursive) throws IOException {\n    try {\n      return innerDelete(getFileStatus(path), recursive);\n    } catch (FileNotFoundException e) {\n      LOG.debug(\"Couldn't delete {} - does not exist\", path);\n      return false;\n    }\n  }\n\n  /**\n   * Delete an object. See {@link #delete(Path, boolean)}.","sourceCodeStart":149,"sourceCodeEnd":185,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-tools/hadoop-aliyun/src/main/java/org/apache/hadoop/fs/aliyun/oss/AliyunOSSFileSystem.java#L149-L185","documentation":"Thrown by AliyunOSSFileSystem.createNonRecursive(): it stats the parent of the target path and requires it to be an existing directory. If getFileStatus(parent) succeeds but reports a file, the parent cannot hold children in OSS's flat key space, so it fails fast with FileAlreadyExistsException(\"Not a directory: \" + parent).","triggerScenarios":"Calling createNonRecursive() where some ancestor key exists as a file object — e.g., creating oss://bucket/a/b when object 'a' exists as a file; mixing file and directory usage of the same name in a key hierarchy.","commonSituations":"Data lakes where an earlier job wrote a file at a path now used as a partition directory; malformed generated paths (a file name reused as a directory prefix); copying HDFS trees that contained file/dir name collisions normalized differently.","solutions":["Find and remove or rename the file occupying the parent path (e.g., oss://bucket/a) so the directory structure can exist","Fix the writer to use consistent path layout so a given name is only ever a file or a directory, never both","Use ls/getFileStatus on the parent before createNonRecursive to give a clearer application-level error"],"exampleFix":"// before\nfs.createNonRecursive(new Path(\"oss://bucket/a/b\"), perm, flags, buf, rep, block, null);\n// 'a' exists as a file\n\n// after\n// remove or relocate object 'a', then create the directory first\nfs.mkdirs(new Path(\"oss://bucket/a\"));\nfs.createNonRecursive(new Path(\"oss://bucket/a/b\"), perm, flags, buf, rep, block, null);","handlingStrategy":"validation","validationCode":"Path parent = path.getParent();\nif (!fs.exists(parent) || !fs.getFileStatus(parent).isDirectory()) {\n  throw new IOException(\"Parent missing or not a directory: \" + parent);\n}\nfs.createNonRecursive(path, perm, flags, buf, rep, block, null);","typeGuard":null,"tryCatchPattern":"catch (FileAlreadyExistsException e) { /* parent is a file: surface which ancestor conflicts and fail */ throw e; }","preventionTips":["Verify each output parent is an existing directory before createNonRecursive","Enforce a layout where a name is only ever a file or a directory, never both"],"tags":["aliyun-oss","path-conflict","parent-not-directory","hadoop-connector"],"backgroundTag":"parent-path-is-file","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}