apache/hadoop · error · IllegalArgumentException

Number of maps is invalid: {value}

Error message

Number of maps is invalid: {value}

What it means

The -m (max maps) option value must parse as a Java int. Integer.parseInt failed and OptionsParser rethrows IllegalArgumentException with the raw value. Note the option only sets the maximum map count; decimal values, commas, or suffixed numbers ('1k', '10.5', '1,000') all fail parsing.

Source

Thrown at hadoop-tools/hadoop-distcp/src/main/java/org/apache/hadoop/tools/OptionsParser.java:191

        DistCpOptionSwitch.NUM_LISTSTATUS_THREADS.getSwitch())) {
      try {
        final Integer numThreads = Integer.parseInt(getVal(command,
            DistCpOptionSwitch.NUM_LISTSTATUS_THREADS.getSwitch()));
        builder.withNumListstatusThreads(numThreads);
      } catch (NumberFormatException e) {
        throw new IllegalArgumentException(
            "Number of liststatus threads is invalid: " + getVal(command,
                DistCpOptionSwitch.NUM_LISTSTATUS_THREADS.getSwitch()), e);
      }
    }

    if (command.hasOption(DistCpOptionSwitch.MAX_MAPS.getSwitch())) {
      try {
        final Integer maps = Integer.parseInt(
            getVal(command, DistCpOptionSwitch.MAX_MAPS.getSwitch()));
        builder.maxMaps(maps);
      } catch (NumberFormatException e) {
        throw new IllegalArgumentException("Number of maps is invalid: " +
            getVal(command, DistCpOptionSwitch.MAX_MAPS.getSwitch()), e);
      }
    }

    if (command.hasOption(DistCpOptionSwitch.COPY_STRATEGY.getSwitch())) {
      builder.withCopyStrategy(
            getVal(command, DistCpOptionSwitch.COPY_STRATEGY.getSwitch()));
    }

    if (command.hasOption(DistCpOptionSwitch.PRESERVE_STATUS.getSwitch())) {
      builder.preserve(
          getVal(command, DistCpOptionSwitch.PRESERVE_STATUS.getSwitch()));
    }

    if (command.hasOption(DistCpOptionSwitch.FILE_LIMIT.getSwitch())) {
      LOG.warn(DistCpOptionSwitch.FILE_LIMIT.getSwitch() + " is a deprecated" +
          " option. Ignoring.");
    }

View on GitHub (pinned to 2add963021)

Solutions

  1. Pass a plain integer, e.g. -m 20.
  2. Strip separators/suffixes from templated values.
  3. Sanity-check the value in the wrapper: it must match ^[0-9]+$ (or a signed int).

Example fix

# before
hadoop distcp -m 10.5 hdfs://nn/src hdfs://nn/tgt

# after
hadoop distcp -m 10 hdfs://nn/src hdfs://nn/tgt
Defensive patterns

Strategy: validation

Validate before calling

// Wrapper validation: -m must be a plain integer
if (!args[i].equals("-m") && !args[i].startsWith("--")) { /* pass */ }
String v = args[i + 1];
if (!v.matches("[0-9]+")) {
  throw new IllegalArgumentException("-m must be an integer, got: " + v);
}

Try / catch

try {
  OptionsParser.parse(args);
} catch (IllegalArgumentException e) {
  if (e.getMessage().startsWith("Number of maps is invalid")) {
    throw new IllegalArgumentException("Fix -m to a plain integer", e);
  }
  throw e;
}

Prevention

When it happens

Trigger: -m 10.5, -m 1,000, -m 20m, or an empty interpolated variable.

Common situations: operators writing decimal map counts; human-readable suffixed numbers from runbooks; template scripts inserting formatted numbers.

Related errors


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