{"record":{"id":"de7f96607f31483d","repo":"apache/hadoop","slug":"wrong-fs-path-expected-this-geturi","errorCode":null,"errorMessage":"Wrong FS: {path}, expected: {this.getUri()}","messagePattern":"Wrong FS: (.+?), expected: (.+?)","errorType":"validation","errorClass":"InvalidPathException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/AbstractFileSystem.java","lineNumber":395,"sourceCode":"        }\n        throw new InvalidPathException(\"relative paths not allowed:\" + \n            path);\n      } else {\n        throw new InvalidPathException(\n            \"Path without scheme with non-null authority:\" + path);\n      }\n    }\n    String thisScheme = this.getUri().getScheme();\n    String thisHost = this.getUri().getHost();\n    String thatHost = uri.getHost();\n    \n    // Schemes and hosts must match.\n    // Allow for null Authority for file:///\n    if (!thisScheme.equalsIgnoreCase(thatScheme) ||\n       (thisHost != null && \n            !thisHost.equalsIgnoreCase(thatHost)) ||\n       (thisHost == null && thatHost != null)) {\n      throw new InvalidPathException(\"Wrong FS: \" + path + \", expected: \"\n          + this.getUri());\n    }\n    \n    // Ports must match, unless this FS instance is using the default port, in\n    // which case the port may be omitted from the given URI\n    int thisPort = this.getUri().getPort();\n    int thatPort = uri.getPort();\n    if (thatPort == -1) { // -1 => defaultPort of Uri scheme\n      thatPort = this.getUriDefaultPort();\n    }\n    if (thisPort != thatPort) {\n      throw new InvalidPathException(\"Wrong FS: \" + path\n          + \" and port=\" + thatPort\n          + \", expected: \"\n          + this.getUri()\n          + \" with port=\" + thisPort);\n    }\n  }","sourceCodeStart":377,"sourceCodeEnd":413,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/AbstractFileSystem.java#L377-L413","documentation":"AbstractFileSystem.checkPath requires the path's scheme and host (both case-insensitive) to match the FS instance's own URI; it also rejects a path with a host when this instance has none. Operating on a path that belongs to a different cluster or filesystem through the wrong handle throws InvalidPathException(\"Wrong FS: ...\").","triggerScenarios":"An AbstractFileSystem/FileSystem handle created for hdfs://clusterA used with a path hdfs://clusterB/x; passing file:///tmp/x to an HDFS instance; an instance whose URI has null host (file:///) given a path carrying a host.","commonSituations":"Cached FileSystem instances reused across clusters in a long-lived service; migration/distcp jobs carrying absolute source-cluster paths; wrong fs.defaultFS; viewfs mount tables routing to a different nameservice than the handle.","solutions":["Operate on each path with its own handle: FileSystem.get(path.toUri(), conf) or use FileContext, which resolves the FS per path","Fix fs.defaultFS / HA nameservice config so the handle matches the paths","For cross-filesystem copies, use FileUtil.copy(srcFS, src, dstFS, dst, deleteSource, overwrite) instead of single-handle operations"],"exampleFix":"// before\nFileSystem hA = FileSystem.get(new URI(\"hdfs://clusterA:8020\"), conf);\nhA.rename(new Path(\"hdfs://clusterB:8020/x\"), new Path(\"hdfs://clusterB:8020/y\")); // Wrong FS\n\n// after\nFileSystem hB = FileSystem.get(new Path(\"hdfs://clusterB:8020/x\").toUri(), conf);\nhB.rename(new Path(\"/x\"), new Path(\"/y\"));","handlingStrategy":"validation","validationCode":"URI fsUri = afs.getUri();\nURI pUri = p.toUri();\nboolean schemeOk = pUri.getScheme() != null && fsUri.getScheme().equalsIgnoreCase(pUri.getScheme());\nboolean hostOk = fsUri.getHost() == null ? pUri.getHost() == null : fsUri.getHost().equalsIgnoreCase(pUri.getHost());\nif (!schemeOk || !hostOk) {\n  afs = AbstractFileSystem.get(pUri, conf); // rebind to the path's own file system\n}","typeGuard":null,"tryCatchPattern":"catch (InvalidPathException e) { if (e.getMessage().startsWith(\"Wrong FS\")) { afs = AbstractFileSystem.get(p.toUri(), conf); /* retry with correct handle */ } else throw e; }","preventionTips":["Derive the handle from the path (FileSystem.get(path.toUri(), conf)) instead of reusing a cached one","Use FileContext, which resolves the file system per path","For cross-cluster work use FileUtil.copy between two handles rather than single-handle ops"],"tags":["hadoop","filesystem","uri","mismatch","configuration"],"backgroundTag":"filesystem-mismatch","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}