apache/hadoop · error · HadoopIllegalArgumentException
Expect either -getlevel or -setlevel
Error message
Expect either -getlevel or -setlevel
What it means
LogLevel.CLI.sendLogLevelRequest dispatches on the parsed operation enum and throws HadoopIllegalArgumentException from the default branch when the operation is neither GETLEVEL nor SETLEVEL. In the stock run() flow this is a defensive duplicate of the check in parseArguments (which normally rejects such inputs first, see 'Must specify either -getlevel or -setlevel'); it fires standalone only when the internal operation state was never set before sending.
Source
Thrown at hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/log/LogLevel.java:136
return 0;
}
/**
* Send HTTP/HTTPS request to the daemon.
* @throws HadoopIllegalArgumentException if arguments are invalid.
* @throws Exception if unable to connect
*/
private void sendLogLevelRequest()
throws HadoopIllegalArgumentException, Exception {
switch (operation) {
case GETLEVEL:
doGetLevel();
break;
case SETLEVEL:
doSetLevel();
break;
default:
throw new HadoopIllegalArgumentException(
"Expect either -getlevel or -setlevel");
}
}
public void parseArguments(String[] args) throws
HadoopIllegalArgumentException {
if (args.length == 0) {
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 {View on GitHub (pinned to 2add963021)
Solutions
- Always run parseArguments(args) to completion (it sets the operation) before calling sendLogLevelRequest().
- Or drive the tool the supported way — ToolRunner.run(new CLI(conf), args) / 'hadoop loglevel ...' — which enforces the argument checks for you.
- If you keep programmatic use, verify operation != Operations.UNKNOWN before sending and fail with your own message.
Example fix
// before CLI cli = new CLI(conf); cli.sendLogLevelRequest(); // operation still UNKNOWN // after CLI cli = new CLI(conf); ToolRunner.run(cli, args); // parses args, sets operation, then sends
Defensive patterns
Strategy: validation
Validate before calling
// Ensure arguments were parsed (operation set) before sending the request
if (operation == Operations.UNKNOWN) {
throw new HadoopIllegalArgumentException(
"No operation parsed; call parseArguments(args) with -getlevel/-setlevel first");
}
sendLogLevelRequest(); Prevention
- Use ToolRunner.run(new CLI(conf), args) instead of driving CLI internals directly.
- If embedding, always run parseArguments() successfully before sendLogLevelRequest().
- Unit-test the embedded flow with empty and flag-only args to assert the operation guard fires.
When it happens
Trigger: Calling sendLogLevelRequest() programmatically without a prior successful parseArguments(); a subclass or test resetting operation state to UNKNOWN before the request is sent.
Common situations: Embedding or unit-testing LogLevel.CLI internals; refactors that bypass the normal run()/parseArguments path.
Related errors
- "Unexpected argument " + args[nextArgIndex]
- Must specify either -getlevel or -setlevel
- 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/11eb60a3e2d2f96c.
Report an issue: GitHub.