{"record":{"id":"48faef9e9e8732dc","repo":"apache/hadoop","slug":"failed-to-rename-s-to-s-s-is-a-file-48faef","errorCode":null,"errorMessage":"Failed to rename %s to %s, %s is a file","messagePattern":"Failed to rename (.+?) to (.+?), (.+?) is a file","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"hadoop-tools/hadoop-aliyun/src/main/java/org/apache/hadoop/fs/aliyun/oss/AliyunOSSFileSystem.java","lineNumber":647,"sourceCode":"    Path parent = dstPath.getParent();\n    while (parent != null && !srcPath.equals(parent)) {\n      parent = parent.getParent();\n    }\n    if (parent != null) {\n      return false;\n    }\n    FileStatus srcStatus = getFileStatus(srcPath);\n    FileStatus dstStatus;\n    try {\n      dstStatus = getFileStatus(dstPath);\n    } catch (FileNotFoundException fnde) {\n      dstStatus = null;\n    }\n    if (dstStatus == null) {\n      // If dst doesn't exist, check whether dst dir exists or not\n      dstStatus = getFileStatus(dstPath.getParent());\n      if (!dstStatus.isDirectory()) {\n        throw new IOException(String.format(\n            \"Failed to rename %s to %s, %s is a file\", srcPath, dstPath,\n            dstPath.getParent()));\n      }\n    } else {\n      if (srcStatus.getPath().equals(dstStatus.getPath())) {\n        return !srcStatus.isDirectory();\n      } else if (dstStatus.isDirectory()) {\n        // If dst is a directory\n        dstPath = new Path(dstPath, srcPath.getName());\n        FileStatus[] statuses;\n        try {\n          statuses = listStatus(dstPath);\n        } catch (FileNotFoundException fnde) {\n          statuses = null;\n        }\n        if (statuses != null && statuses.length > 0) {\n          // If dst exists and not a directory / not empty\n          throw new FileAlreadyExistsException(String.format(","sourceCodeStart":629,"sourceCodeEnd":665,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-tools/hadoop-aliyun/src/main/java/org/apache/hadoop/fs/aliyun/oss/AliyunOSSFileSystem.java#L629-L665","documentation":"Thrown by AliyunOSSFileSystem.rename(): the destination path itself does not exist, so the code stats the destination's parent and requires it to be a directory. When that parent exists but is a file, the renamed object would land 'inside' a file key, which OSS cannot represent, so it throws IOException(\"Failed to rename %s to %s, %s is a file\").","triggerScenarios":"Calling rename(src, dst) where dst is absent and dst.getParent() exists as a file object — e.g., rename(oss://bucket/f, oss://bucket/a/g) while 'a' is a file; typically from committers or Hive moving files into partition paths.","commonSituations":"Partition directories whose prefix is occupied by an old data file; staging/commit moves into paths whose parents were written as files by other tools; renaming to a mistyped destination under a file-like prefix.","solutions":["Delete or rename the file object at the parent path so the directory structure can exist, then retry the rename","Correct the destination path if the parent was mistyped","Create the destination directory first (fs.mkdirs(dst.getParent())) after resolving the conflict"],"exampleFix":"// before\nfs.rename(new Path(\"oss://b/f\"), new Path(\"oss://b/a/g\")); // 'a' is a file\n\n// after\n// resolve 'a': remove the file, then ensure the directory exists\nfs.delete(new Path(\"oss://b/a\"), false);\nfs.mkdirs(new Path(\"oss://b/a\"));\nfs.rename(new Path(\"oss://b/f\"), new Path(\"oss://b/a/g\"));","handlingStrategy":"validation","validationCode":"Path parent = dst.getParent();\nif (!fs.exists(dst)) {\n  if (!fs.exists(parent) || !fs.getFileStatus(parent).isDirectory()) {\n    throw new IOException(\"rename dst parent is not a directory: \" + parent);\n  }\n}\nfs.rename(src, dst);","typeGuard":null,"tryCatchPattern":"catch (IOException e) { if (e.getMessage().contains(\"is a file\")) { /* clean the file at dst parent or fix dst path */ } throw e; }","preventionTips":["Validate the destination parent is an existing directory before rename","Keep partition directories free of file objects at the same key"],"tags":["aliyun-oss","rename","parent-not-directory","hadoop-connector"],"backgroundTag":"rename-destination-parent-is-file","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}