apache/hadoop · error · RenameFailedException

cannot rename a directory to a subdirectory of itself

Error message

cannot rename a directory to a subdirectory of itself 

What it means

Error "cannot rename a directory to a subdirectory of itself " thrown in apache/hadoop.

Source

Thrown at hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/impl/RenameOperation.java:364

  /**
   * Execute a full recursive rename.
   * There is a special handling of directly markers here -only leaf markers
   * are copied. This reduces incompatibility "regions" across versions.
   * @throws IOException failure
   */
  protected void recursiveDirectoryRename() throws IOException {
    final StoreContext storeContext = getStoreContext();

    LOG.debug("rename: renaming directory {} to {}", sourcePath, destPath);

    // This is a directory-to-directory copy
    String dstKey = maybeAddTrailingSlash(destKey);
    String srcKey = maybeAddTrailingSlash(sourceKey);

    // Verify dest is not a child of the source directory
    if (dstKey.startsWith(srcKey)) {
      throw new RenameFailedException(srcKey, dstKey,
          "cannot rename a directory to a subdirectory of itself ");
    }
    // start the async dir cleanup
    final CompletableFuture<Long> abortUploads;
    if (dirOperationsPurgeUploads) {
      final String key = srcKey;
      LOG.debug("All uploads under {} will be deleted", key);
      abortUploads = submit(getStoreContext().getExecutor(), () ->
          callbacks.abortMultipartUploadsUnderPrefix(key));
    } else {
      abortUploads = null;
    }

    if (destStatus != null
        && destStatus.isEmptyDirectory() == Tristate.TRUE) {
      // delete unnecessary fake directory at the destination.

      LOG.debug("Deleting fake directory marker at destination {}",

View on GitHub (pinned to 2add963021)

Solutions

  1. Choose a destination that is not inside the source directory.

When it happens

Trigger: Thrown at hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/impl/RenameOperation.java:364 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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