{"record":{"id":"7f585e488fccfdc5","repo":"apache/hadoop","slug":"failed-to-rename-s-to-s","errorCode":null,"errorMessage":"Failed to rename %s to %s","messagePattern":"Failed to rename (.+?) to (.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"hadoop-cloud-storage-project/hadoop-tos/src/main/java/org/apache/hadoop/fs/tosfs/object/FileStore.java","lineNumber":578,"sourceCode":"    File file = path(encode(srcKey)).toFile();\n    if (!file.exists()) {\n      throw new RuntimeException(String.format(\"File not found %s\", file.getAbsolutePath()));\n    }\n\n    put(dstKey, () -> get(srcKey).stream(), file.length());\n  }\n\n  @Override\n  public void rename(String srcKey, String dstKey) {\n    Preconditions.checkArgument(!Objects.equals(srcKey, dstKey),\n        \"Cannot rename to the same object\");\n    Preconditions.checkNotNull(head(srcKey), \"Source key %s doesn't exist\", srcKey);\n\n    File srcFile = path(encode(srcKey)).toFile();\n    File dstFile = path(encode(dstKey)).toFile();\n    boolean ret = srcFile.renameTo(dstFile);\n    if (!ret) {\n      throw new RuntimeException(String.format(\"Failed to rename %s to %s\", srcKey, dstKey));\n    }\n  }\n\n  @Override\n  public ObjectInfo objectStatus(String key) {\n    ObjectInfo obj = head(key);\n    if (obj == null && !ObjectInfo.isDir(key)) {\n      key = key + '/';\n      obj = head(key);\n    }\n\n    if (obj == null) {\n      Iterable<ObjectInfo> objs = list(key, null, 1);\n      if (objs.iterator().hasNext()) {\n        obj = new ObjectInfo(key, 0, new Date(0), Constants.MAGIC_CHECKSUM);\n      }\n    }\n","sourceCodeStart":560,"sourceCodeEnd":596,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-cloud-storage-project/hadoop-tos/src/main/java/org/apache/hadoop/fs/tosfs/object/FileStore.java#L560-L596","documentation":"FileStore.rename implements ObjectStorage.rename with java.io.File.renameTo(src, dst). That JVM method returns false instead of throwing on failure (cross-filesystem rename, missing destination parent, permission denied, destination locked by an open handle on Windows), and the connector converts the false into RuntimeException(\"Failed to rename <srcKey> to <dstKey>\").","triggerScenarios":"Renaming between keys that resolve to different mount points/devices under the store root; the destination parent directory not existing; no write/execute permission on the target directory; destination or source file held open (mainly Windows); the source removed by a concurrent process between checkNotNull and renameTo.","commonSituations":"Store root spanning multiple filesystems or symlinked to another volume; running as a user without write permission on the directory; Windows dev/test boxes with open file handles; concurrent jobs renaming the same key.","solutions":["Ensure both keys live on the same filesystem/volume under the store root","Create the destination parent directory before renaming","Check OS write permissions on both parent directories","Fall back to copy(srcKey, dstKey) followed by delete(srcKey) when renameTo keeps failing","Close any open streams referencing src or dst before renaming (mainly Windows)"],"exampleFix":"// before\nstorage.rename(srcKey, dstKey);\n\n// after: portable copy+delete fallback\ntry {\n  storage.rename(srcKey, dstKey);\n} catch (RuntimeException e) {\n  if (e.getMessage() != null && e.getMessage().startsWith(\"Failed to rename\")) {\n    storage.copy(srcKey, dstKey);\n    storage.delete(srcKey);\n  } else {\n    throw e;\n  }\n}","handlingStrategy":"fallback","validationCode":"// ensure destination parent exists before renaming\njava.nio.file.Path dst = storeRoot.resolve(encode(dstKey));\njava.nio.file.Path parent = dst.getParent();\nif (parent != null && !java.nio.file.Files.exists(parent)) {\n  java.nio.file.Files.createDirectories(parent);\n}","typeGuard":null,"tryCatchPattern":"try {\n  storage.rename(srcKey, dstKey);\n} catch (RuntimeException e) {\n  if (e.getMessage() != null && e.getMessage().startsWith(\"Failed to rename\")) {\n    storage.copy(srcKey, dstKey);\n    storage.delete(srcKey);\n  } else {\n    throw e;\n  }\n}","preventionTips":["Keep the store root on a single filesystem/volume","Pre-create destination parent directories before rename","Close open stream handles before renaming (mainly Windows)","Have a copy+delete fallback for cross-volume portability"],"tags":["hadoop-tos","object-storage","local-filesystem","rename","filesystem-permissions"],"backgroundTag":"file-rename-failed","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}