apache/hadoop · error · IllegalArgumentException

Invalid URI for NameNode address (check %s): %s is not of sc

Error message

Invalid URI for NameNode address (check %s): %s is not of scheme '%s'.

What it means

The second half of getNNAddress(URI)'s validation: after confirming an authority exists, the URI's scheme must equal 'hdfs' (case-insensitive) because the returned address is the HDFS RPC NameNode endpoint. Any other scheme — webhdfs, swebhdfs, file, s3a, viewfs — produces IllegalArgumentException('Invalid URI for NameNode address (check fs.defaultFS): ... is not of scheme hdfs.'), again pointing at fs.defaultFS.

Source

Thrown at hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/DFSUtilClient.java:892

  public static InetSocketAddress getNNAddress(Configuration conf) {
    URI filesystemURI = FileSystem.getDefaultUri(conf);
    return getNNAddressCheckLogical(conf, filesystemURI);
  }

  /**
   * @return address of file system
   */
  public static InetSocketAddress getNNAddress(URI filesystemURI) {
    String authority = filesystemURI.getAuthority();
    if (authority == null) {
      throw new IllegalArgumentException(String.format(
          "Invalid URI for NameNode address (check %s): %s has no authority.",
          FileSystem.FS_DEFAULT_NAME_KEY, filesystemURI.toString()));
    }
    if (!HdfsConstants.HDFS_URI_SCHEME.equalsIgnoreCase(
        filesystemURI.getScheme())) {
      throw new IllegalArgumentException(String.format(
          "Invalid URI for NameNode address (check %s): " +
          "%s is not of scheme '%s'.", FileSystem.FS_DEFAULT_NAME_KEY,
          filesystemURI.toString(), HdfsConstants.HDFS_URI_SCHEME));
    }
    return getNNAddress(authority);
  }

  /**
   * Get the NN address from the URI. If the uri is logical, default address is
   * returned. Otherwise return the DNS-resolved address of the URI.
   *
   * @param conf configuration
   * @param filesystemURI URI of the file system
   * @return address of file system
   */
  public static InetSocketAddress getNNAddressCheckLogical(Configuration conf,
      URI filesystemURI) {
    InetSocketAddress retAddr;

View on GitHub (pinned to 2add963021)

Solutions

  1. Set fs.defaultFS to hdfs://<host:port|logical-name> for components that talk to the HDFS NameNode.
  2. Gate the call: HdfsConstants.HDFS_URI_SCHEME.equalsIgnoreCase(uri.getScheme()) before invoking getNNAddress(URI).
  3. Use scheme-appropriate helpers (WebHDFS address APIs for webhdfs/swebhdfs) instead of the HDFS RPC resolver.
  4. Fail fast at startup with a clear message when a component requires HDFS but the default FS scheme differs.

Example fix

// before
InetSocketAddress nn = DFSUtilClient.getNNAddress(FileSystem.getDefaultUri(conf)); // file:/// -> throws

// after
URI uri = FileSystem.getDefaultUri(conf);
if (!HdfsConstants.HDFS_URI_SCHEME.equalsIgnoreCase(uri.getScheme())) {
  throw new IllegalStateException("This tool requires fs.defaultFS=hdfs://..., got: " + uri);
}
InetSocketAddress nn = DFSUtilClient.getNNAddress(uri);
Defensive patterns

Strategy: validation

Validate before calling

URI defaultUri = FileSystem.getDefaultUri(conf);
if (!HdfsConstants.HDFS_URI_SCHEME.equalsIgnoreCase(defaultUri.getScheme())) {
  throw new IllegalStateException(
      "HDFS client component requires fs.defaultFS scheme 'hdfs', got: "
          + defaultUri);
}
return DFSUtilClient.getNNAddress(defaultUri);

Type guard

boolean isHdfsUri =
    HdfsConstants.HDFS_URI_SCHEME.equalsIgnoreCase(uri.getScheme())
        && uri.getAuthority() != null;

Try / catch

try {
  return DFSUtilClient.getNNAddress(uri);
} catch (IllegalArgumentException e) {
  throw new ConfigurationException(
      "Wrong default filesystem for HDFS access: " + e.getMessage(), e);
}

Prevention

When it happens

Trigger: Calling getNNAddress with a non-hdfs URI: fs.defaultFS set to 'file:///' (local/debug mode), a 'webhdfs://nn:9870' HTTP endpoint passed where the RPC endpoint is required, or tooling that forwards an arbitrary user URI into this HDFS-specific helper.

Common situations: Applications run in local mode whose default FS is file:/// but a component assumes HDFS; mixing WebHDFS HTTP URIs and HDFS client URIs; test fixtures with generic URIs reaching HDFS-specific code.

Related errors


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