{"record":{"id":"55874e605a534df2","repo":"apache/hadoop","slug":"wrong-fs-path-expected-this-geturi-55874e","errorCode":null,"errorMessage":"Wrong FS: ${path}, expected: ${this.getUri()}","messagePattern":"Wrong FS: (.+?), expected: (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileSystem.java","lineNumber":823,"sourceCode":"          thisAuthority != null) {                // fs has an authority\n        URI defaultUri = getDefaultUri(getConf());\n        if (thisScheme.equalsIgnoreCase(defaultUri.getScheme())) {\n          uri = defaultUri; // schemes match, so use this uri instead\n        } else {\n          uri = null; // can't determine auth of the path\n        }\n      }\n      if (uri != null) {\n        // canonicalize uri before comparing with this fs\n        uri = canonicalizeUri(uri);\n        thatAuthority = uri.getAuthority();\n        if (thisAuthority == thatAuthority ||       // authorities match\n            (thisAuthority != null &&\n             thisAuthority.equalsIgnoreCase(thatAuthority)))\n          return;\n      }\n    }\n    throw new IllegalArgumentException(\"Wrong FS: \" + path +\n                                       \", expected: \" + this.getUri());\n  }\n\n  /**\n   * Return an array containing hostnames, offset and size of\n   * portions of the given file.  For nonexistent\n   * file or regions, {@code null} is returned.\n   *\n   * <pre>\n   *   if f == null :\n   *     result = null\n   *   elif f.getLen() {@literal <=} start:\n   *     result = []\n   *   else result = [ locations(FS, b) for b in blocks(FS, p, s, s+l)]\n   * </pre>\n   * This call is most helpful with and distributed filesystem\n   * where the hostnames of machines that contain blocks of the given file\n   * can be determined.","sourceCodeStart":805,"sourceCodeEnd":841,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileSystem.java#L805-L841","documentation":"checkPath (invoked by open/create/getFileStatus and friends) qualifies the given Path and compares its scheme and authority with this FileSystem's URI; on mismatch it throws IllegalArgumentException('Wrong FS: path, expected: thisUri'). A FileSystem instance can only operate inside its own namespace, so paths from another store or authority are rejected.","triggerScenarios":"Passing a fully-qualified path from another filesystem to this instance: an hdfs://nn:8020/... path to a LocalFileSystem or the reverse, a path whose authority (nameservice ID, host:port) differs from the instance's URI, or a viewfs mount prefix mismatch.","commonSituations":"Hardcoded hdfs:// URLs executed in local unit tests; HA configs where the path uses the NameService ID but the FileSystem was created from an rpc-address authority; distcp-style flows where a path is handed to the wrong FileSystem object.","solutions":["Resolve the FileSystem from the path itself: FileSystem fs = path.getFileSystem(conf)","Or use unqualified (relative) paths when operating through FileSystem.get(conf) on the default FS","Verify the authority spelling (host, port, nameservice ID) in both fs.defaultFS and the path","For cross-store work, open each side through its own FileSystem and stream the copy"],"exampleFix":"// before\nFileSystem local = FileSystem.getLocal(conf);\nFSDataInputStream in = local.open(new Path(\"hdfs://nn:8020/data/f\")); // Wrong FS\n\n// after\nPath p = new Path(\"hdfs://nn:8020/data/f\");\nFSDataInputStream in = p.getFileSystem(conf).open(p);","handlingStrategy":"validation","validationCode":"public static FileSystem fsFor(FileSystem current, Path p, Configuration conf) throws IOException {\n  URI pu = p.toUri();\n  URI cu = current.getUri();\n  boolean schemeOk = pu.getScheme() == null || pu.getScheme().equalsIgnoreCase(cu.getScheme());\n  boolean authOk = pu.getAuthority() == null || pu.getAuthority().equalsIgnoreCase(cu.getAuthority());\n  return (schemeOk && authOk) ? current : p.getFileSystem(conf);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never hardcode absolute URIs in job code; use relative paths plus the default FS","Derive the FileSystem from the Path, not from a constant instance","Keep authority spelling (nameservice/host/port) consistent between paths and fs.defaultFS"],"tags":["hadoop","filesystem","path","uri-mismatch","checkpath"],"backgroundTag":"filesystem-path-mismatch","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}