{"record":{"id":"837494edda7c13a5","repo":"apache/hadoop","slug":"name-is-not-a-valid-inet-address","errorCode":null,"errorMessage":"${name} is not a valid Inet address","messagePattern":"(.+?) is not a valid Inet address","errorType":"exception","errorClass":"UnknownHostException","httpStatus":null,"severity":"warning","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/net/NetUtils.java","lineNumber":693,"sourceCode":"  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  }\n\n  private static final Pattern ipPortPattern = // Pattern for matching ip[:port]\n    Pattern.compile(\"\\\\d{1,3}\\\\.\\\\d{1,3}\\\\.\\\\d{1,3}\\\\.\\\\d{1,3}(:\\\\d+)?\");\n  \n  /**\n   * Attempt to obtain the host name of the given string which contains\n   * an IP address and an optional port.\n   * \n   * @param ipPort string of form ip[:port]\n   * @return Host name or null if the name can not be determined\n   */\n  public static String getHostNameOfIP(String ipPort) {\n    if (null == ipPort || !ipPortPattern.matcher(ipPort).matches()) {\n      return null;\n    }","sourceCodeStart":675,"sourceCodeEnd":711,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/net/NetUtils.java#L675-L711","documentation":"UnknownHostException from NetUtils.verifyHostnames when a non-null entry cannot be coerced into a URI with a host: neither new URI(name) nor the retry new URI(\"http://\" + name) yields a non-null getHost(). This rejects names whose syntax is too broken to even extract a hostname (URISyntaxException in both attempts, or a URI with no host component). It is a syntax check, not a DNS check — nothing is resolved.","triggerScenarios":"Entries containing spaces, '_', '{', '}', '|' or other characters illegal in URI hosts; names like 'host name' or 'host:port:extra'; empty strings after trim; entries that are bare schemes ('http://') with no host.","commonSituations":"Hand-edited host lists with stray characters; templating bugs injecting blanks; users assuming this does DNS resolution and being confused when a resolvable-but-weird name (e.g., with underscore) still fails.","solutions":["Correct the entry to a plain hostname, FQDN, IP, or scheme://host form without illegal characters","Replace underscores and spaces (illegal in URI hosts) with dashes","Pre-validate entries with the same URI trick (new URI(name) / new URI(\"http://\" + name)) to catch bad values at config load time"],"exampleFix":"// before\nNetUtils.verifyHostnames(new String[] { \"my_host.example.com\" }); // '_' illegal in URI host -> UnknownHostException\n\n// after\nNetUtils.verifyHostnames(new String[] { \"my-host.example.com\" });","handlingStrategy":"validation","validationCode":"static boolean looksLikeHostname(String name) {\n  try {\n    URI u = new URI(name);\n    if (u.getHost() == null) u = new URI(\"http://\" + name);\n    return u.getHost() != null;\n  } catch (URISyntaxException e) { return false; }\n}","typeGuard":null,"tryCatchPattern":"catch (UnknownHostException e) { /* '<name> is not a valid Inet address' */ it is a syntax failure, not DNS: fix characters (spaces, underscores, extra colons) and re-validate; }","preventionTips":["Use plain hostnames/FQDNs/IPs; avoid characters illegal in URI hosts (space, underscore, braces)","Remember verifyHostnames checks syntax only — do not rely on it for reachability","Pre-validate generated host lists with the same URI trick in tests"],"tags":["hostname","validation","uri-parsing","hadoop-common"],"backgroundTag":"hostname-validation-failed","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}