apache/hadoop · error · IllegalArgumentException

Invalid hostname provided '%s'

Error message

Invalid hostname provided '%s'

What it means

After tokenizing, NfsExports classifies the lowercased host token: '*' becomes an anonymous match, CIDR short (d.d.d.d/n) or long (d.d.d.d/d.d.d.d) forms, a regex match if the token contains * ? [ ] ( ), or an exact match if it is an RFC-1123 hostname (labels of 1-63 letters/digits/hyphens, no leading/trailing hyphen). A token fitting none of these throws IllegalArgumentException('Invalid hostname provided').

Source

Thrown at hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/nfs/NfsExports.java:406

      if (LOG.isDebugEnabled()) {
        LOG.debug("Using CIDR match for '" + host + "' and " + privilege);
      }
      String[] pair = host.split("/");
      return new CIDRMatch(privilege,
          new SubnetUtils(pair[0], pair[1]).getInfo());
    } else if (host.contains("*") || host.contains("?") || host.contains("[")
        || host.contains("]") || host.contains("(") || host.contains(")")) {
      if (LOG.isDebugEnabled()) {
        LOG.debug("Using Regex match for '" + host + "' and " + privilege);
      }
      return new RegexMatch(privilege, host);
    } else if (HOSTNAME_FORMAT.matcher(host).matches()) {
      if (LOG.isDebugEnabled()) {
        LOG.debug("Using exact match for '" + host + "' and " + privilege);
      }
      return new ExactMatch(privilege, host);
    } else {
      throw new IllegalArgumentException("Invalid hostname provided '" + host
          + "'");
    }
  }
}

View on GitHub (pinned to 2add963021)

Solutions

  1. Replace underscores with hyphens in the exports entry, or use a wildcard regex form (any token containing * or ? is treated as a regex)
  2. Use IPv4/CIDR or RFC-1123 hostname forms only; this parser has no IPv6 branch
  3. Validate each entry (hostname regex or InetAddress parse) before adding it to nfs.exports

Example fix

# before
web_01.example.com rw

# after
web-01.example.com rw
Defensive patterns

Strategy: validation

Validate before calling

private static final Pattern LABEL =
    Pattern.compile("[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?");

boolean ok = host.equals("*")
    || host.matches("\\d+\\.\\d+\\.\\d+\\.\\d+/\\d+") // CIDR
    || ("*?[]()".chars().anyMatch(c -> host.indexOf(c) >= 0)) // regex forms
    || LABEL.matcher(host).matches() && host.equals(host); // hostname labels joined by dots
if (!ok) throw new IllegalArgumentException("Unsupported host entry: " + host);

Prevention

When it happens

Trigger: Host tokens containing underscores (web_01.example.com), IPv6 addresses (colons match nothing), malformed IPs like 192.168.0.256, stray punctuation, or trailing dots — none satisfies the CIDR patterns or HOSTNAME_FORMAT.

Common situations: Corporate machine names with underscores (legal on Windows networks, illegal as RFC-1121/1123 hostnames); IPv6-only clients; typos introduced while editing nfs.exports.

Related errors


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