apache/hadoop · error · HadoopIllegalArgumentException
Must specify either -getlevel or -setlevel
Error message
Must specify either -getlevel or -setlevel
What it means
After the whole argument vector parses cleanly, LogLevel.CLI verifies an operation was actually selected; if operation is still UNKNOWN it throws HadoopIllegalArgumentException. This catches inputs where every token was individually valid but none of them chose -getlevel/-setlevel — the classic case being '-protocol http' alone.
Source
Thrown at hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/log/LogLevel.java:162
throw new HadoopIllegalArgumentException("No arguments specified");
}
int nextArgIndex = 0;
while (nextArgIndex < args.length) {
if (args[nextArgIndex].equals("-getlevel")) {
nextArgIndex = parseGetLevelArgs(args, nextArgIndex);
} else if (args[nextArgIndex].equals("-setlevel")) {
nextArgIndex = parseSetLevelArgs(args, nextArgIndex);
} else if (args[nextArgIndex].equals("-protocol")) {
nextArgIndex = parseProtocolArgs(args, nextArgIndex);
} else {
throw new HadoopIllegalArgumentException(
"Unexpected argument " + args[nextArgIndex]);
}
}
// if operation is never specified in the arguments
if (operation == Operations.UNKNOWN) {
throw new HadoopIllegalArgumentException(
"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) {View on GitHub (pinned to 2add963021)
Solutions
- Add the missing operation flag: '-getlevel <host:port> <classname>' or '-setlevel <host:port> <classname> <level>'.
- Fix the constructing script so the operation variable cannot expand to nothing.
- Check the printed usage (run() calls printUsage on this failure) and mirror its exact shape.
Example fix
# before hadoop loglevel -protocol https namenode:9871 # after hadoop loglevel -getlevel namenode:9871 org.apache.hadoop.ipc.Server -protocol https
Defensive patterns
Strategy: validation
Validate before calling
boolean hasOp = Arrays.stream(args).anyMatch(a -> a.equals("-getlevel") || a.equals("-setlevel"));
if (!hasOp) {
throw new HadoopIllegalArgumentException("Must include -getlevel or -setlevel");
}
ToolRunner.run(new LogLevel.CLI(conf), args); Prevention
- Always include one operation flag; -protocol alone does nothing.
- In scripts, verify the OPERATION variable is set before building the command.
- Remember the tool defaults only the protocol (http), never the operation.
When it happens
Trigger: Running 'hadoop loglevel -protocol http' (protocol given, no operation); passing only generic options that survive into the parser as no-ops; a script that assembles the command but drops the operation flag due to an empty variable.
Common situations: Copy-paste commands that lost their first token; scripts where the OPERATION variable is empty; users assuming the tool defaults to -getlevel when only a protocol is given.
Related errors
- Expect either -getlevel or -setlevel
- "Unexpected argument " + args[nextArgIndex]
- No arguments specified
- Redundant -getlevel command
- -getlevel needs two parameters
AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22).
Data as JSON: /api/errors/8c485efa31862840.
Report an issue: GitHub.