apache/hadoop · error · IllegalArgumentException

Wrong FS: ${path}, expected: ${this.getUri()}

Error message

Wrong FS: ${path}, expected: ${this.getUri()}

What it means

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.

Source

Thrown at hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileSystem.java:823

          thisAuthority != null) {                // fs has an authority
        URI defaultUri = getDefaultUri(getConf());
        if (thisScheme.equalsIgnoreCase(defaultUri.getScheme())) {
          uri = defaultUri; // schemes match, so use this uri instead
        } else {
          uri = null; // can't determine auth of the path
        }
      }
      if (uri != null) {
        // canonicalize uri before comparing with this fs
        uri = canonicalizeUri(uri);
        thatAuthority = uri.getAuthority();
        if (thisAuthority == thatAuthority ||       // authorities match
            (thisAuthority != null &&
             thisAuthority.equalsIgnoreCase(thatAuthority)))
          return;
      }
    }
    throw new IllegalArgumentException("Wrong FS: " + path +
                                       ", expected: " + this.getUri());
  }

  /**
   * Return an array containing hostnames, offset and size of
   * portions of the given file.  For nonexistent
   * file or regions, {@code null} is returned.
   *
   * <pre>
   *   if f == null :
   *     result = null
   *   elif f.getLen() {@literal <=} start:
   *     result = []
   *   else result = [ locations(FS, b) for b in blocks(FS, p, s, s+l)]
   * </pre>
   * This call is most helpful with and distributed filesystem
   * where the hostnames of machines that contain blocks of the given file
   * can be determined.

View on GitHub (pinned to 2add963021)

Solutions

  1. Resolve the FileSystem from the path itself: FileSystem fs = path.getFileSystem(conf)
  2. Or use unqualified (relative) paths when operating through FileSystem.get(conf) on the default FS
  3. Verify the authority spelling (host, port, nameservice ID) in both fs.defaultFS and the path
  4. For cross-store work, open each side through its own FileSystem and stream the copy

Example fix

// before
FileSystem local = FileSystem.getLocal(conf);
FSDataInputStream in = local.open(new Path("hdfs://nn:8020/data/f")); // Wrong FS

// after
Path p = new Path("hdfs://nn:8020/data/f");
FSDataInputStream in = p.getFileSystem(conf).open(p);
Defensive patterns

Strategy: validation

Validate before calling

public static FileSystem fsFor(FileSystem current, Path p, Configuration conf) throws IOException {
  URI pu = p.toUri();
  URI cu = current.getUri();
  boolean schemeOk = pu.getScheme() == null || pu.getScheme().equalsIgnoreCase(cu.getScheme());
  boolean authOk = pu.getAuthority() == null || pu.getAuthority().equalsIgnoreCase(cu.getAuthority());
  return (schemeOk && authOk) ? current : p.getFileSystem(conf);
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22). Data as JSON: /api/errors/55874e605a534df2. Report an issue: GitHub.