apache/hadoop · error · HadoopIllegalArgumentException

-getlevel needs two parameters

Error message

-getlevel needs two parameters

What it means

-getlevel consumes exactly two following parameters: <host:port> and <classname>. parseGetLevelArgs checks index+2 >= args.length and throws HadoopIllegalArgumentException('-getlevel needs two parameters') when the classname (or both) is missing. Note the check is strict about position: the last usable token must sit at index+2, so a trailing -protocol flag directly after the host does not satisfy it.

Source

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

            "Must specify either -getlevel or -setlevel");
      }

      // if protocol is unspecified, set it as http.
      if (protocol == null) {
        protocol = PROTOCOL_HTTP;
      }
    }

    private int parseGetLevelArgs(String[] args, int index) throws
        HadoopIllegalArgumentException {
      // fail if multiple operations are specified in the arguments
      if (operation != Operations.UNKNOWN) {
        throw new HadoopIllegalArgumentException(
            "Redundant -getlevel command");
      }
      // check number of arguments is sufficient
      if (index+2 >= args.length) {
        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(

View on GitHub (pinned to 2add963021)

Solutions

  1. Provide both parameters in order: '-getlevel <host:port> <fully.qualified.ClassName>'.
  2. If you also want -protocol, place it after the two parameters: '-getlevel host:port cls -protocol https'.
  3. Fix the calling script so host and class variables are both non-empty.

Example fix

# before
hadoop loglevel -getlevel namenode:9870

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

Strategy: validation

Validate before calling

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

Prevention

When it happens

Trigger: 'hadoop loglevel -getlevel namenode:9870' (classname forgotten); '-getlevel' as the final token; ordering mistakes like '-getlevel -protocol http ...' where the next tokens are flags, not parameters.

Common situations: Truncated commands from copy-paste; scripts forgetting the classname argument; users assuming the class is optional (it is not — it selects the logger).

Related errors


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