{"record":{"id":"48ef4d069c07d806","repo":"apache/hadoop","slug":"invalid-uri-for-namenode-address-check-s-s-is","errorCode":null,"errorMessage":"Invalid URI for NameNode address (check %s): %s is not of scheme '%s'.","messagePattern":"Invalid URI for NameNode address \\(check (.+?)\\): (.+?) is not of scheme '(.+?)'\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/DFSUtilClient.java","lineNumber":892,"sourceCode":"\n  public static InetSocketAddress getNNAddress(Configuration conf) {\n    URI filesystemURI = FileSystem.getDefaultUri(conf);\n    return getNNAddressCheckLogical(conf, filesystemURI);\n  }\n\n  /**\n   * @return address of file system\n   */\n  public static InetSocketAddress getNNAddress(URI filesystemURI) {\n    String authority = filesystemURI.getAuthority();\n    if (authority == null) {\n      throw new IllegalArgumentException(String.format(\n          \"Invalid URI for NameNode address (check %s): %s has no authority.\",\n          FileSystem.FS_DEFAULT_NAME_KEY, filesystemURI.toString()));\n    }\n    if (!HdfsConstants.HDFS_URI_SCHEME.equalsIgnoreCase(\n        filesystemURI.getScheme())) {\n      throw new IllegalArgumentException(String.format(\n          \"Invalid URI for NameNode address (check %s): \" +\n          \"%s is not of scheme '%s'.\", FileSystem.FS_DEFAULT_NAME_KEY,\n          filesystemURI.toString(), HdfsConstants.HDFS_URI_SCHEME));\n    }\n    return getNNAddress(authority);\n  }\n\n  /**\n   * Get the NN address from the URI. If the uri is logical, default address is\n   * returned. Otherwise return the DNS-resolved address of the URI.\n   *\n   * @param conf configuration\n   * @param filesystemURI URI of the file system\n   * @return address of file system\n   */\n  public static InetSocketAddress getNNAddressCheckLogical(Configuration conf,\n      URI filesystemURI) {\n    InetSocketAddress retAddr;","sourceCodeStart":874,"sourceCodeEnd":910,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/DFSUtilClient.java#L874-L910","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Set fs.defaultFS to hdfs://<host:port|logical-name> for components that talk to the HDFS NameNode.","Gate the call: HdfsConstants.HDFS_URI_SCHEME.equalsIgnoreCase(uri.getScheme()) before invoking getNNAddress(URI).","Use scheme-appropriate helpers (WebHDFS address APIs for webhdfs/swebhdfs) instead of the HDFS RPC resolver.","Fail fast at startup with a clear message when a component requires HDFS but the default FS scheme differs."],"exampleFix":"// before\nInetSocketAddress nn = DFSUtilClient.getNNAddress(FileSystem.getDefaultUri(conf)); // file:/// -> throws\n\n// after\nURI uri = FileSystem.getDefaultUri(conf);\nif (!HdfsConstants.HDFS_URI_SCHEME.equalsIgnoreCase(uri.getScheme())) {\n  throw new IllegalStateException(\"This tool requires fs.defaultFS=hdfs://..., got: \" + uri);\n}\nInetSocketAddress nn = DFSUtilClient.getNNAddress(uri);","handlingStrategy":"validation","validationCode":"URI defaultUri = FileSystem.getDefaultUri(conf);\nif (!HdfsConstants.HDFS_URI_SCHEME.equalsIgnoreCase(defaultUri.getScheme())) {\n  throw new IllegalStateException(\n      \"HDFS client component requires fs.defaultFS scheme 'hdfs', got: \"\n          + defaultUri);\n}\nreturn DFSUtilClient.getNNAddress(defaultUri);","typeGuard":"boolean isHdfsUri =\n    HdfsConstants.HDFS_URI_SCHEME.equalsIgnoreCase(uri.getScheme())\n        && uri.getAuthority() != null;","tryCatchPattern":"try {\n  return DFSUtilClient.getNNAddress(uri);\n} catch (IllegalArgumentException e) {\n  throw new ConfigurationException(\n      \"Wrong default filesystem for HDFS access: \" + e.getMessage(), e);\n}","preventionTips":["Fail fast when HDFS-only components see a non-hdfs default FS (local mode 'file:///' is the classic case).","Route scheme-specific URI handling to scheme-specific helpers instead of one generic resolver."],"tags":["hdfs","namenode","uri","scheme","configuration","argument-validation"],"backgroundTag":"invalid-endpoint-uri","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}