{"record":{"id":"11133628dfd39b69","repo":"apache/hadoop","slug":"null-hostname-found","errorCode":null,"errorMessage":"null hostname found","messagePattern":"null hostname found","errorType":"exception","errorClass":"UnknownHostException","httpStatus":null,"severity":"warning","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/net/NetUtils.java","lineNumber":678,"sourceCode":"   */\n  public static List<String> normalizeHostNames(Collection<String> names) {\n    List<String> hostNames = new ArrayList<String>(names.size());\n    for (String name : names) {\n      hostNames.add(normalizeHostName(name));\n    }\n    return hostNames;\n  }\n\n  /**\n   * Performs a sanity check on the list of hostnames/IPs to verify they at least\n   * appear to be valid.\n   * @param names - List of hostnames/IPs\n   * @throws UnknownHostException Unknown Host Exception.\n   */\n  public static void verifyHostnames(String[] names) throws UnknownHostException {\n    for (String name: names) {\n      if (name == null) {\n        throw new UnknownHostException(\"null hostname found\");\n      }\n      // The first check supports URL formats (e.g. hdfs://, etc.). \n      // java.net.URI requires a schema, so we add a dummy one if it doesn't\n      // have one already.\n      URI uri = null;\n      try {\n        uri = new URI(name);\n        if (uri.getHost() == null) {\n          uri = new URI(\"http://\" + name);\n        }\n      } catch (URISyntaxException e) {\n        uri = null;\n      }\n      if (uri == null || uri.getHost() == null) {\n        throw new UnknownHostException(name + \" is not a valid Inet address\");\n      }\n    }\n  }","sourceCodeStart":660,"sourceCodeEnd":696,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/net/NetUtils.java#L660-L696","documentation":"UnknownHostException('null hostname found') from NetUtils.verifyHostnames — a validation helper that sanity-checks an array of hostnames/IPs (typically proxy or cluster node lists). It throws on the first null entry before doing any URI-based syntax checks. Its presence means the caller passed an array containing nulls, which usually traces back to how the list was built (e.g., splitting an empty or malformed config string).","triggerScenarios":"verifyHostnames(new String[] { \"host1\", null, \"host2\" }); arrays produced by a config split where a token was empty and stored as null; code mapping an optional setting straight into the array without a null filter.","commonSituations":"Proxy configurations (e.g., hadoop.http.proxy...) where an unset optional host leaks null into the list; list parsing that uses a map returning null for missing keys; refactors changing array construction order.","solutions":["Filter nulls out of the array before validation: Arrays.stream(names).filter(Objects::nonNull)","Fix the upstream list construction so empty config tokens are dropped rather than stored as null","Log the raw array (with null markers) when validation fails to identify the producing property"],"exampleFix":"// before\nString[] hosts = parseHosts(conf); // may contain nulls\nNetUtils.verifyHostnames(hosts); // UnknownHostException: null hostname found\n\n// after\nString[] hosts = Arrays.stream(parseHosts(conf))\n    .filter(Objects::nonNull).toArray(String[]::new);\nNetUtils.verifyHostnames(hosts);","handlingStrategy":"validation","validationCode":"boolean hasNull = Arrays.stream(names).anyMatch(Objects::isNull);\nif (hasNull) throw new IllegalStateException(\"host array contains null entries (check list construction)\");","typeGuard":"static String[] nonNullHosts(String[] names) {\n  return names == null ? new String[0]\n      : Arrays.stream(names).filter(Objects::nonNull).toArray(String[]::new);\n}","tryCatchPattern":null,"preventionTips":["Never build host arrays from optional config without filtering nulls","Drop empty tokens during config splitting instead of storing them","Log arrays with null markers before validation in debug tooling"],"tags":["hostname","validation","null-check","hadoop-common"],"backgroundTag":"hostname-validation-failed","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}