apache/hadoop · error · IllegalArgumentException

Incorrectly formatted line '%s'

Error message

Incorrectly formatted line '%s'

What it means

hadoop-nfs NfsExports parses each exports line by splitting on whitespace (line.split("\\s+")); an entry may contain at most two tokens: 'client-hosts' and an optional access privilege ('rw'). A line yielding three or more tokens throws IllegalArgumentException naming the offending line.

Source

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

   * "client-hosts [access-privilege]"
   */
  private static Match getMatch(String line) {
    String[] parts = line.split("\\s+");
    final String host;
    AccessPrivilege privilege = AccessPrivilege.READ_ONLY;
    switch (parts.length) {
    case 1:
      host = StringUtils.toLowerCase(parts[0]).trim();
      break;
    case 2:
      host = StringUtils.toLowerCase(parts[0]).trim();
      String option = parts[1].trim();
      if ("rw".equalsIgnoreCase(option)) {
        privilege = AccessPrivilege.READ_WRITE;
      }
      break;
    default:
      throw new IllegalArgumentException("Incorrectly formatted line '" + line
          + "'");
    }
    if (host.equals("*")) {
      if (LOG.isDebugEnabled()) {
        LOG.debug("Using match all for '" + host + "' and " + privilege);
      }
      return new AnonymousMatch(privilege);
    } else if (CIDR_FORMAT_SHORT.matcher(host).matches()) {
      if (LOG.isDebugEnabled()) {
        LOG.debug("Using CIDR match for '" + host + "' and " + privilege);
      }
      return new CIDRMatch(privilege, new SubnetUtils(host).getInfo());
    } else if (CIDR_FORMAT_LONG.matcher(host).matches()) {
      if (LOG.isDebugEnabled()) {
        LOG.debug("Using CIDR match for '" + host + "' and " + privilege);
      }
      String[] pair = host.split("/");
      return new CIDRMatch(privilege,

View on GitHub (pinned to 2add963021)

Solutions

  1. Reduce each entry to one or two tokens: "host" or "host rw" (read-only is the default; any second token other than rw still means read-only)
  2. Remove standard NFS options like sync, no_root_squash, insecure — the gateway format does not support them
  3. Put comments on separate lines rather than appended after an entry

Example fix

# before (nfs.exports)
192.168.0.0/24 rw sync no_root_squash

# after
192.168.0.0/24 rw
Defensive patterns

Strategy: validation

Validate before calling

private static final Pattern ENTRY = Pattern.compile("^\\S+(\\s+(rw|ro))?$");

for (String line : lines) {
  if (!ENTRY.matcher(line).matches()) {
    throw new IllegalArgumentException("Bad nfs.exports entry (max 2 tokens): " + line);
  }
}
NfsExports.getInstance(matchHosts, cacheSize);

Prevention

When it happens

Trigger: An nfs.exports entry like "192.168.0.0/24 rw sync" or "host rw ro" — classic NFS mount options (sync, no_root_squash, insecure) are not part of this format and become a third token.

Common situations: Copying entries verbatim from /etc/exports of a real NFS server into the Hadoop NFS gateway's nfs.exports file/property; appending same-line comments; listing multiple options separated by spaces.

Related errors


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