{"record":{"id":"5c5ba26bbb4689c3","repo":"apache/hadoop","slug":"wrong-fs-path-and-port-thatport-expected-t","errorCode":null,"errorMessage":"Wrong FS: {path} and port={thatPort}, expected: {this.getUri()} with port={thisPort}","messagePattern":"Wrong FS: (.+?) and port=(.+?), expected: (.+?) with port=(.+?)","errorType":"validation","errorClass":"InvalidPathException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/AbstractFileSystem.java","lineNumber":407,"sourceCode":"    // 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  }\n  \n  /**\n   * Get the path-part of a pathname. Checks that URI matches this file system\n   * and that the path-part is a valid name.\n   * \n   * @param p path\n   * \n   * @return path-part of the Path p\n   */\n  public String getUriPath(final Path p) {\n    checkPath(p);\n    String s = p.toUri().getPath();","sourceCodeStart":389,"sourceCodeEnd":425,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/AbstractFileSystem.java#L389-L425","documentation":"After scheme and host match, AbstractFileSystem.checkPath compares ports: a path port of -1 is resolved to this FS's default port (getUriDefaultPort()), and any remaining difference throws InvalidPathException(\"Wrong FS ... and port=...\"). The path and the handle must agree on port once defaults are applied.","triggerScenarios":"Handle created from hdfs://nn:9000 but path says hdfs://nn:8020/x (or vice versa); handle bound to a non-default port while the path omits the port (resolving to the scheme default); NameNode RPC port changed on one side of the config only.","commonSituations":"Mixing the 8020 and 9000 port conventions between client config and hardcoded paths; stale cached handles after a cluster port change; some tools writing the port into paths while others rely on fs.defaultFS.","solutions":["Use one URI consistently for both the handle and the paths (create the handle from the path's own URI)","Prefer HA logical URIs (hdfs://myNameservice, port omitted) so port comparison never fires","Align fs.defaultFS and any hardcoded host:port in configs/paths"],"exampleFix":"// before\nFileSystem fs = FileSystem.get(new URI(\"hdfs://nn:9000\"), conf);\nfs.exists(new Path(\"hdfs://nn:8020/x\")); // Wrong FS ... port=8020 ... with port=9000\n\n// after\nFileSystem fs = FileSystem.get(new Path(\"hdfs://nn:8020/x\").toUri(), conf);\nfs.exists(new Path(\"/x\"));","handlingStrategy":"validation","validationCode":"int thatPort = p.toUri().getPort();\nif (thatPort == -1) thatPort = afs.getUriDefaultPort();\nif (afs.getUri().getPort() != thatPort) {\n  afs = AbstractFileSystem.get(p.toUri(), conf); // port mismatch: use the path's own FS\n}","typeGuard":null,"tryCatchPattern":"catch (InvalidPathException e) { if (e.getMessage().contains(\"and port=\")) { /* port mismatch: rebind handle to path URI and retry */ } else throw e; }","preventionTips":["Standardize on one RPC port (or HA logical URIs with no port) across all configs","Create handles from the same URI string used in the paths","Avoid hardcoding ports in paths; let fs.defaultFS supply them"],"tags":["hadoop","filesystem","port","uri","mismatch"],"backgroundTag":"filesystem-port-mismatch","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}