apache/hadoop · error · HadoopIllegalArgumentException
Did not expect argument: {}
Error message
Did not expect argument: {} What it means
'hdfs getconf' maps each mode (-namenodes, -secondaryNodes, -backupNodes, -includeFile, -excludeFile, -nnrpcaddresses) to a CommandHandler. The base checkArgs enforces that these modes take zero positional arguments; if any leftover argument remains after option parsing, it is rejected with this HadoopIllegalArgumentException naming the first unexpected token.
Source
Thrown at hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/GetConf.java:170
CommandHandler(String key) {
this.key = key;
}
final int doWork(GetConf tool, String[] args) {
try {
checkArgs(args);
return doWorkInternal(tool, args);
} catch (Exception e) {
tool.printError(e.getMessage());
}
return -1;
}
protected void checkArgs(String args[]) {
if (args.length > 0) {
throw new HadoopIllegalArgumentException(
"Did not expect argument: " + args[0]);
}
}
/** Method to be overridden by sub classes for specific behavior */
int doWorkInternal(GetConf tool, String[] args) throws Exception {
String value = tool.getConf().getTrimmed(key);
if (value != null) {
tool.printOut(value);
return 0;
}
tool.printError("Configuration " + key + " is missing.");
return -1;
}
}
View on GitHub (pinned to 2add963021)
Solutions
- Drop the positional argument: 'hdfs getconf -namenodes' with nothing after it.
- Check 'hdfs getconf' with no arguments to list all modes and which ones take operands (only -confKey takes one).
- In scripts, quote the whole command so stray empty arguments are not appended.
Example fix
# before hdfs getconf -namenodes ns1 # Did not expect argument: ns1 # after hdfs getconf -namenodes
Defensive patterns
Strategy: validation
Validate before calling
// zero-operand getconf modes
String[] positional = argsAfterOptions;
if (positional.length > 0) {
throw new IllegalArgumentException(
"this getconf mode takes no positional argument: " + positional[0]);
}
ToolRunner.run(new GetConf(), fullArgs); Try / catch
try {
return ToolRunner.run(new GetConf(conf), argv);
} catch (Exception e) {
// GetConf.doWork already prints e.getMessage(); a nonzero exit means bad usage
System.err.println("getconf usage: run 'hdfs getconf' with no args to list modes");
return -1;
} Prevention
- Remember only -confKey takes an operand; all other getconf modes are bare flags.
- In scripts use arrays and skip empty parameters instead of always appending variables.
When it happens
Trigger: Running 'hdfs getconf -namenodes someArg', or any getconf mode that expects no operand given a trailing token — often a value the user assumed the mode accepts.
Common situations: Users trying 'hdfs getconf -excludeFile host1' expecting a filtered answer; shell scripts passing an always-present argument variable that is empty-string handled differently; copy-paste from dfsadmin syntax.
Related errors
- usage: -confKey [key]
- Invalid or extra Arguments: {}
- invalid args: {}
- Unknown processor {} (valid processors: xml, binary, stats)
- Illegal option {}
AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22).
Data as JSON: /api/errors/5e5ebc9268a6d67c.
Report an issue: GitHub.