apache/hadoop · error · HadoopIllegalArgumentException

-setlevel needs three parameters

Error message

-setlevel needs three parameters

What it means

-setlevel consumes exactly three following parameters: <host:port>, <classname>, and <level>. parseSetLevelArgs checks index+3 >= args.length and throws HadoopIllegalArgumentException('-setlevel needs three parameters') when the level (or classname, or both) is absent. The level string is taken verbatim (e.g. DEBUG, INFO); validation of it as a real log4j level happens server-side, not here.

Source

Thrown at hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/log/LogLevel.java:199

        throw new HadoopIllegalArgumentException(
            "-getlevel needs two parameters");
      }
      operation = Operations.GETLEVEL;
      hostName = args[index+1];
      className = args[index+2];
      return index+3;
    }

    private int parseSetLevelArgs(String[] args, int index) throws
        HadoopIllegalArgumentException {
      // fail if multiple operations are specified in the arguments
      if (operation != Operations.UNKNOWN) {
        throw new HadoopIllegalArgumentException(
            "Redundant -setlevel command");
      }
      // check number of arguments is sufficient
      if (index+3 >= args.length) {
        throw new HadoopIllegalArgumentException(
            "-setlevel needs three parameters");
      }
      operation = Operations.SETLEVEL;
      hostName = args[index+1];
      className = args[index+2];
      level = args[index+3];
      return index+4;
    }

    private int parseProtocolArgs(String[] args, int index) throws
        HadoopIllegalArgumentException {
      // make sure only -protocol is specified
      if (protocol != null) {
        throw new HadoopIllegalArgumentException(
            "Redundant -protocol command");
      }
      // check number of arguments is sufficient
      if (index+1 >= args.length) {

View on GitHub (pinned to 2add963021)

Solutions

  1. Supply all three parameters in order: '-setlevel <host:port> <classname> <LEVEL>'.
  2. Place -protocol after the three parameters, never between them.
  3. Guard automation scripts: fail early if any of HOST/CLASS/LEVEL is unset.

Example fix

# before
hadoop loglevel -setlevel namenode:9870 org.apache.hadoop.ipc.Server

# after
hadoop loglevel -setlevel namenode:9870 org.apache.hadoop.ipc.Server DEBUG
Defensive patterns

Strategy: validation

Validate before calling

int i = Arrays.asList(args).indexOf("-setlevel");
if (i >= 0 && (i + 3 >= args.length
      || args[i+1].startsWith("-") || args[i+2].startsWith("-") || args[i+3].startsWith("-"))) {
  throw new HadoopIllegalArgumentException(
      "-setlevel needs host:port, classname, and level as the next three tokens");
}

Prevention

When it happens

Trigger: 'hadoop loglevel -setlevel namenode:9870 org.apache.hadoop.ipc.Server' (level omitted); -setlevel as the last token; trailing -protocol flag positioned where the level was expected ('-setlevel h cls -protocol https' consumes '-protocol' as the level and then fails on 'https').

Common situations: Forgetting the new level when scripting runtime log changes; parameter order confusion; empty $LEVEL variable in automation dropping the third argument.

Related errors


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