{"record":{"id":"51b93a8900389baf","repo":"apache/hadoop","slug":"path-is-a-directory","errorCode":null,"errorMessage":"{path} is a directory","messagePattern":"(.+?) is 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":128,"sourceCode":"      super.close();\n    }\n  }\n\n  @Override\n  public FSDataOutputStream create(Path path, FsPermission permission,\n      boolean overwrite, int bufferSize, short replication, long blockSize,\n      Progressable progress) throws IOException {\n    String key = pathToKey(path);\n    FileStatus status = null;\n\n    try {\n      // get the status or throw a FNFE\n      status = getFileStatus(path);\n\n      // if the thread reaches here, there is something at the path\n      if (status.isDirectory()) {\n        // path references a directory\n        throw new FileAlreadyExistsException(path + \" is a directory\");\n      }\n      if (!overwrite) {\n        // path references a file and overwrite is disabled\n        throw new FileAlreadyExistsException(path + \" already exists\");\n      }\n      LOG.debug(\"Overwriting file {}\", path);\n    } catch (FileNotFoundException e) {\n      // this means the file is not found\n    }\n\n    return new FSDataOutputStream(\n        new AliyunOSSBlockOutputStream(getConf(),\n            store,\n            key,\n            uploadPartSize,\n            blockFactory,\n            blockOutputStreamStatistics,\n            new SemaphoredDelegatingExecutor(boundedThreadPool,","sourceCodeStart":110,"sourceCodeEnd":146,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-tools/hadoop-aliyun/src/main/java/org/apache/hadoop/fs/aliyun/oss/AliyunOSSFileSystem.java#L110-L146","documentation":"Thrown by AliyunOSSFileSystem.create(): getFileStatus(path) found an existing entry and it is a directory. Since a directory marker (or any object under the prefix) occupies that path, create() cannot place a file there regardless of overwrite, so it fails with FileAlreadyExistsException(path + \" is a directory\").","triggerScenarios":"Calling create() (directly or via OutputFormat/checkpoint writer) on a path that already exists as a directory in OSS; e.g., writing to oss://bucket/logs when 'logs/' exists as a directory marker or contains child objects.","commonSituations":"Output paths colliding with existing directory prefixes (data lake partition directories); a job's _temporary layout or a previous run leaving a directory at the target; recursive directory structures where a file path equals an existing partition path.","solutions":["Choose a distinct file name or path for the output (e.g., include a timestamp/part suffix) so it does not collide with the directory","Delete or rename the conflicting directory first if it is stale output from a previous run","Fix the job configuration so the output committer writes files inside the directory rather than over the directory path itself"],"exampleFix":"// before\nfs.create(new Path(\"oss://bucket/events\")); // events/ is a directory\n\n// after\nfs.create(new Path(\"oss://bucket/events/part-0000\"));","handlingStrategy":"validation","validationCode":"Path out = new Path(\"oss://bucket/events\");\nif (fs.exists(out) && fs.getFileStatus(out).isDirectory()) {\n  throw new IOException(\"Refusing to create file over directory \" + out);\n}\nfs.create(out);","typeGuard":null,"tryCatchPattern":"catch (FileAlreadyExistsException e) { /* create() hit a directory: pick a new file path or clean the directory */ }","preventionTips":["Pre-check fs.exists + isDirectory on output paths before create()","Make output file names leaf paths (include part/attempt id), never the same string as an existing partition directory"],"tags":["aliyun-oss","path-conflict","directory-exists","hadoop-connector"],"backgroundTag":"output-path-is-directory","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}