apache/hadoop · error · HadoopIllegalArgumentException
"Invalid protocol: " + protocol
Error message
"Invalid protocol: " + protocol
What it means
After -protocol consumes its single parameter, LogLevel.isValidProtocol accepts only the exact lowercase strings 'http' and 'https' (PROTOCOL_HTTP/PROTOCOL_HTTPS, compared with equals). Anything else — 'HTTP', 'Http', 'hdfs', 'hadooprpc' — throws HadoopIllegalArgumentException('Invalid protocol: ...'). The scheme also decides which client path runs: doGetLevel/doSetLevel use AuthenticatedURL and SSLFactory accordingly.
Source
Thrown at hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/log/LogLevel.java:224
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) {
throw new HadoopIllegalArgumentException(
"-protocol needs one parameter");
}
// check protocol is valid
protocol = args[index+1];
if (!isValidProtocol(protocol)) {
throw new HadoopIllegalArgumentException(
"Invalid protocol: " + protocol);
}
return index+2;
}
/**
* Send HTTP/HTTPS request to get log level.
*
* @throws HadoopIllegalArgumentException if arguments are invalid.
* @throws Exception if unable to connect
*/
private void doGetLevel() throws Exception {
process(protocol + "://" + hostName + "/logLevel?log=" + className);
}
/**
* Send HTTP/HTTPS request to set log level.
*View on GitHub (pinned to 2add963021)
Solutions
- Use exactly 'http' or 'https' in lowercase.
- Normalize in scripts: SCHEME=$(echo "$SCHEME" | tr 'A-Z' 'a-z') and strip whitespace.
- If the daemon's admin UI is SSL-enabled, remember it must be https with the proper SSLFactory setup on the daemon side.
Example fix
# before hadoop loglevel -getlevel nn:9871 cls -protocol HTTPS # after hadoop loglevel -getlevel nn:9871 cls -protocol https
Defensive patterns
Strategy: validation
Validate before calling
if (!LogLevel.isValidProtocol(scheme)) {
throw new HadoopIllegalArgumentException(
"protocol must be exactly 'http' or 'https' (lowercase), got: " + scheme);
}
// or reuse the public helper directly: LogLevel.isValidProtocol(args[i+1]) Type guard
boolean isSupportedLogLevelProtocol(String s) {
return s != null && ("http".equals(s) || "https".equals(s));
} Prevention
- Type the scheme in lowercase exactly: http or https.
- Normalize scheme variables in scripts: tr 'A-Z' 'a-z' and trim whitespace.
- Use https only when the daemon's admin UI is SSL-enabled; otherwise the request fails later with a connection error.
When it happens
Trigger: '-protocol HTTP' or '-protocol Https' (case mismatch); '-protocol hdfs' or other scheme names; values with trailing whitespace or quotes from shell expansion.
Common situations: Uppercase scheme habits from URLs/browsers; scripts passing a generic $SCHEME variable used for other tools; quoting artifacts from wrappers.
Related errors
- Redundant -protocol command
- -protocol needs one parameter
- Expect either -getlevel or -setlevel
- No arguments specified
- "Unexpected argument " + args[nextArgIndex]
AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22).
Data as JSON: /api/errors/009e0d1f7ba34ae8.
Report an issue: GitHub.