{"record":{"id":"8c95bb683ce27937","repo":"apache/hadoop","slug":"rename-from-to-failed","errorCode":null,"errorMessage":"rename from {} to {} failed.","messagePattern":"rename from (.+?) to (.+?) failed\\.","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileSystem.java","lineNumber":1724,"sourceCode":"          throw new IOException(\n              \"rename cannot overwrite non empty destination directory \" + dst);\n        }\n      }\n      delete(dst, false);\n    } else {\n      final Path parent = dst.getParent();\n      final FileStatus parentStatus = getFileStatus(parent);\n      if (parentStatus == null) {\n        throw new FileNotFoundException(\"rename destination parent \" + parent\n            + \" not found.\");\n      }\n      if (!parentStatus.isDirectory()) {\n        throw new ParentNotDirectoryException(\"rename destination parent \" + parent\n            + \" is a file.\");\n      }\n    }\n    if (!rename(src, dst)) {\n      throw new IOException(\"rename from \" + src + \" to \" + dst + \" failed.\");\n    }\n  }\n\n  /**\n   * Truncate the file in the indicated path to the indicated size.\n   * <ul>\n   *   <li>Fails if path is a directory.</li>\n   *   <li>Fails if path does not exist.</li>\n   *   <li>Fails if path is not closed.</li>\n   *   <li>Fails if new size is greater than current size.</li>\n   * </ul>\n   * @param f The path to the file to be truncated\n   * @param newLength The size the file is to be truncated to\n   *\n   * @return <code>true</code> if the file has been truncated to the desired\n   * <code>newLength</code> and is immediately available to be reused for\n   * write operations such as <code>append</code>, or\n   * <code>false</code> if a background process of adjusting the length of","sourceCodeStart":1706,"sourceCodeEnd":1742,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileSystem.java#L1706-L1742","documentation":"The final step of the deprecated options-aware rename calls the abstract rename(src, dst) and converts a false return into IOException('rename from src to dst failed.'). All path preconditions already passed, so false means the filesystem itself refused the move - most often permissions or an OS-level lock, since boolean renames carry no reason.","triggerScenarios":"Underlying rename(Path, Path) returning false: no write permission on the source or destination parent in the store; the source file is open/locked (notably Windows local FS); store errors mapped to false by some object-store clients.","commonSituations":"Running as a user without write access to the destination directory; local tests on Windows moving open files; HDFS lease or safe-mode edge cases surfacing as a false return.","solutions":["Check write permission on both parents for the effective user (and kinit for Kerberos clusters)","Close any open streams/handles on src before renaming (especially local FS on Windows)","Inspect the concrete FileSystem's logs for the store-level reason","For stores with non-atomic rename, fall back to copy + delete with explicit error handling"],"exampleFix":"// before\nfs.rename(src, dst); // underlying false -> IOException: rename ... failed\n\n// after\nif (!fs.rename(src, dst)) {\n  FileContext.getFileContext(conf).util().copy(src, dst); // copy fallback\n  fs.delete(src, false);\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  fs.rename(src, dst, Rename.OVERWRITE);\n} catch (IOException e) {\n  if (e.getMessage() != null && e.getMessage().contains(\"rename from\")) {\n    // preconditions passed but store refused: check perms/locks, then copy+delete\n    FileContext.getFileContext(conf).util().copy(src, dst);\n    fs.delete(src, false);\n  } else {\n    throw e;\n  }\n}","preventionTips":["Verify write access on both source and destination parents before publishing","Close all open streams/handles on files you rename (especially on Windows local FS)","Check the concrete FileSystem logs when a boolean rename fails"],"tags":["hadoop","filesystem","rename","permission-denied","windows-file-lock"],"backgroundTag":"rename-failed","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}