{"record":{"id":"66903901fae73a9f","repo":"apache/hadoop","slug":"cannot-rename-because-path-does-not-exist-s","errorCode":null,"errorMessage":"Cannot rename because path does not exist: %s","messagePattern":"Cannot rename because path does not exist: (.+?)","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"hadoop-cloud-storage-project/hadoop-gcp/src/main/java/org/apache/hadoop/fs/gs/GoogleCloudStorageFileSystem.java","lineNumber":565,"sourceCode":"\n  private URI getDstUri(FileInfo srcInfo, FileInfo dstInfo, @Nullable FileInfo dstParentInfo)\n      throws IOException {\n    URI src = srcInfo.getPath();\n    URI dst = dstInfo.getPath();\n\n    // Throw if src is a file and dst == GCS_ROOT\n    if (!srcInfo.isDirectory() && dst.equals(GCSROOT)) {\n      throw new IOException(\"A file cannot be created in root.\");\n    }\n\n    // Throw if the destination is a file that already exists, and it's not a source file.\n    if (dstInfo.exists() && !dstInfo.isDirectory() && (srcInfo.isDirectory() || !dst.equals(src))) {\n      throw new IOException(\"Cannot overwrite an existing file: \" + dst);\n    }\n\n    // Rename operation cannot be completed if parent of destination does not exist.\n    if (dstParentInfo != null && !dstParentInfo.exists()) {\n      throw new IOException(\n          \"Cannot rename because path does not exist: \" + dstParentInfo.getPath());\n    }\n\n    // Leaf item of the source path.\n    String srcItemName = getItemName(src);\n\n    // Having taken care of the initial checks, apply the regular rules.\n    // After applying the rules, we will be left with 2 paths such that:\n    // -- either both are files or both are directories\n    // -- src exists and dst leaf does not exist\n    if (srcInfo.isDirectory()) {\n      // -- if src is a directory\n      //    -- dst is an existing file => disallowed\n      //    -- dst is a directory => rename the directory.\n\n      // The first case (dst is an existing file) is already checked earlier.\n      // If the destination path looks like a file, make it look like a\n      // directory path. This is because users often type 'mv foo bar'","sourceCodeStart":547,"sourceCodeEnd":583,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-cloud-storage-project/hadoop-gcp/src/main/java/org/apache/hadoop/fs/gs/GoogleCloudStorageFileSystem.java#L547-L583","documentation":"getDstUri validates that the parent of the rename destination exists (dstParentInfo != null && !dstParentInfo.exists()). GCS has no real server-side directories, so the connector checks client-side that the destination's parent path is present (as an object, placeholder, or inferred directory); if not, the rename is rejected.","triggerScenarios":"gcsFs.rename(src, dst) where UriPaths.getParentPath(dst) does not exist, e.g. rename gs://b/src to gs://b/newdir/dst when gs://b/newdir has never been created or written to.","commonSituations":"Destination subdirectories not pre-created because GCS directories are implicit (no placeholder until something is written under them); scripts ported from HDFS assuming rename creates intermediate directories; fresh buckets receiving their first structured data.","solutions":["Create the destination parent before renaming: fs.mkdirs(dst.getParent()) (GCS mkdirs creates placeholder objects).","Rename to a destination directly under an existing directory instead of a new subtree.","Guard with fs.exists(dst.getParent()) and fail fast with a clear application error."],"exampleFix":"// before\nfs.rename(new Path(\"gs://bucket/src\"), new Path(\"gs://bucket/newdir/dst\"));\n// -> IOException: Cannot rename because path does not exist: gs://bucket/newdir\n\n// after\nPath dst = new Path(\"gs://bucket/newdir/dst\");\nif (!fs.exists(dst.getParent())) {\n  fs.mkdirs(dst.getParent());\n}\nfs.rename(new Path(\"gs://bucket/src\"), dst);","handlingStrategy":"validation","validationCode":"Path dst = new Path(\"gs://bucket/newdir/result\");\nif (!fs.exists(dst.getParent())) {\n  fs.mkdirs(dst.getParent()); // creates placeholder objects for GCS directories\n}\nfs.rename(src, dst);","typeGuard":null,"tryCatchPattern":"catch IOException with message contains(\"Cannot rename because path does not exist\") - the message names the missing path; create it with mkdirs and retry once.","preventionTips":["Pre-create destination directory trees with mkdirs before rename stages - GCS directories are implicit.","Remember GCS has no server-side mkdir; the connector validates parents client-side.","In concurrent pipelines, re-verify parents just before renaming."],"tags":["rename","gcs","hadoop","directories","filesystem"],"backgroundTag":"rename-destination-parent-missing","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}