apache/hadoop · error · FileAlreadyExistsException

{path} is a directory

Error message

{path} is a directory

What it means

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").

Source

Thrown at hadoop-tools/hadoop-aliyun/src/main/java/org/apache/hadoop/fs/aliyun/oss/AliyunOSSFileSystem.java:128

      super.close();
    }
  }

  @Override
  public FSDataOutputStream create(Path path, FsPermission permission,
      boolean overwrite, int bufferSize, short replication, long blockSize,
      Progressable progress) throws IOException {
    String key = pathToKey(path);
    FileStatus status = null;

    try {
      // get the status or throw a FNFE
      status = getFileStatus(path);

      // if the thread reaches here, there is something at the path
      if (status.isDirectory()) {
        // path references a directory
        throw new FileAlreadyExistsException(path + " is a directory");
      }
      if (!overwrite) {
        // path references a file and overwrite is disabled
        throw new FileAlreadyExistsException(path + " already exists");
      }
      LOG.debug("Overwriting file {}", path);
    } catch (FileNotFoundException e) {
      // this means the file is not found
    }

    return new FSDataOutputStream(
        new AliyunOSSBlockOutputStream(getConf(),
            store,
            key,
            uploadPartSize,
            blockFactory,
            blockOutputStreamStatistics,
            new SemaphoredDelegatingExecutor(boundedThreadPool,

View on GitHub (pinned to 2add963021)

Solutions

  1. 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
  2. Delete or rename the conflicting directory first if it is stale output from a previous run
  3. Fix the job configuration so the output committer writes files inside the directory rather than over the directory path itself

Example fix

// before
fs.create(new Path("oss://bucket/events")); // events/ is a directory

// after
fs.create(new Path("oss://bucket/events/part-0000"));
Defensive patterns

Strategy: validation

Validate before calling

Path out = new Path("oss://bucket/events");
if (fs.exists(out) && fs.getFileStatus(out).isDirectory()) {
  throw new IOException("Refusing to create file over directory " + out);
}
fs.create(out);

Try / catch

catch (FileAlreadyExistsException e) { /* create() hit a directory: pick a new file path or clean the directory */ }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22). Data as JSON: /api/errors/51b93a8900389baf. Report an issue: GitHub.