{"record":{"id":"123e97e67532fb87","repo":"apache/hadoop","slug":"unsupported-scheme","errorCode":null,"errorMessage":"Unsupported scheme: {}","messagePattern":"Unsupported 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":271,"sourceCode":"      HdfsClientConfigKeys.DFS_NAMENODE_RPC_ADDRESS_KEY);\n  }\n\n  /**\n   * Returns list of InetSocketAddress corresponding to HA NN HTTP addresses from\n   * the configuration.\n   *\n   * @return list of InetSocketAddresses\n   */\n  public static Map<String, Map<String, InetSocketAddress>> getHaNnWebHdfsAddresses(\n      Configuration conf, String scheme) {\n    if (WebHdfsConstants.WEBHDFS_SCHEME.equals(scheme)) {\n      return getAddresses(conf, null,\n          HdfsClientConfigKeys.DFS_NAMENODE_HTTP_ADDRESS_KEY);\n    } else if (WebHdfsConstants.SWEBHDFS_SCHEME.equals(scheme)) {\n      return getAddresses(conf, null,\n          HdfsClientConfigKeys.DFS_NAMENODE_HTTPS_ADDRESS_KEY);\n    } else {\n      throw new IllegalArgumentException(\"Unsupported scheme: \" + scheme);\n    }\n  }\n\n  /**\n   * Convert a LocatedBlocks to BlockLocations[]\n   * @param blocks a LocatedBlocks\n   * @return an array of BlockLocations\n   */\n  public static BlockLocation[] locatedBlocks2Locations(LocatedBlocks blocks) {\n    if (blocks == null) {\n      return new BlockLocation[0];\n    }\n    return locatedBlocks2Locations(blocks.getLocatedBlocks());\n  }\n\n  /**\n   * Convert a List to BlockLocation[]\n   * @param blocks A List to be converted","sourceCodeStart":253,"sourceCodeEnd":289,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/DFSUtilClient.java#L253-L289","documentation":"DFSUtilClient.getHaNnWebHdfsAddresses(conf, scheme) resolves the HA NameNode HTTP addresses for the two WebHDFS schemes: 'webhdfs' maps to dfs.namenode.http-address entries and 'swebhdfs' to dfs.namenode.https-address entries. Any other scheme — including null, 'hdfs', or differently-cased variants — is rejected with IllegalArgumentException('Unsupported scheme: ...') because the helper is WebHDFS-specific.","triggerScenarios":"Calling getHaNnWebHdfsAddresses with a scheme that is not exactly WebHdfsConstants.WEBHDFS_SCHEME ('webhdfs') or SWEBHDFS_SCHEME ('swebhdfs'): passing URI.getScheme() from an hdfs:// URL, forwarding a user-supplied scheme from a proxy/frontend, or a typo/case difference ('WebHDFS').","commonSituations":"Custom WebHDFS proxies or tooling that builds NN web-redirect addresses; code paths that reuse one address-resolution helper for both RPC (hdfs://) and WebHDFS URIs; request handlers trusting the scheme from an incoming URL.","solutions":["Pass the constants: WebHdfsConstants.WEBHDFS_SCHEME or WebHdfsConstants.SWEBHDFS_SCHEME.","Normalize input before the call: trim and lowercase the scheme string, reject null early.","For plain HDFS RPC addresses use the NameNode RPC address helpers (DFSUtil/NameNodeServiceAddresses) instead of the WebHDFS one.","Catch IllegalArgumentException in front-end code to reject malformed requests with a clear message."],"exampleFix":"// before\nMap<String, Map<String, InetSocketAddress>> addrs =\n    DFSUtilClient.getHaNnWebHdfsAddresses(conf, uri.getScheme()); // 'hdfs' -> throws\n\n// after\nString scheme = uri.getScheme() == null ? null : uri.getScheme().toLowerCase(Locale.ROOT);\nif (!WebHdfsConstants.WEBHDFS_SCHEME.equals(scheme)\n    && !WebHdfsConstants.SWEBHDFS_SCHEME.equals(scheme)) {\n  throw new IllegalArgumentException(\"Scheme must be webhdfs or swebhdfs: \" + scheme);\n}\nMap<String, Map<String, InetSocketAddress>> addrs =\n    DFSUtilClient.getHaNnWebHdfsAddresses(conf, scheme);","handlingStrategy":"validation","validationCode":"private static final Set<String> WEBHDFS_SCHEMES =\n    Set.of(WebHdfsConstants.WEBHDFS_SCHEME, WebHdfsConstants.SWEBHDFS_SCHEME);\n\nString scheme = uri.getScheme();\nif (scheme != null) {\n  scheme = scheme.toLowerCase(Locale.ROOT);\n}\nif (!WEBHDFS_SCHEMES.contains(scheme)) {\n  throw new IllegalArgumentException(\n      \"scheme must be one of \" + WEBHDFS_SCHEMES + \", got: \" + scheme);\n}\nreturn DFSUtilClient.getHaNnWebHdfsAddresses(conf, scheme);","typeGuard":null,"tryCatchPattern":"try {\n  return DFSUtilClient.getHaNnWebHdfsAddresses(conf, scheme);\n} catch (IllegalArgumentException e) {\n  // surface a clear 4xx-style error for user-supplied schemes instead of a 500\n  throw new BadRequestException(\"Unsupported webhdfs scheme: \" + scheme);\n}","preventionTips":["Compare against the WebHdfsConstants constants, never hand-typed strings.","Normalize scheme input (trim + lowercase) at the trust boundary.","Note the comparison is case-sensitive equals against lowercase constants — 'WebHdfs' fails validation."],"tags":["hdfs","webhdfs","scheme","argument-validation","configuration"],"backgroundTag":"invalid-uri-scheme","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}