apache/hadoop · error · IllegalArgumentException
invalid args: {}
Error message
invalid args: {} What it means
JMXGet ('hdfs jmxget') parses its command line with commons-cli GnuParser in stop-at-non-option mode. Any ParseException — unknown option, an option like -port missing its value, malformed flags — is caught, the usage is printed, and an IllegalArgumentException prefixed 'invalid args:' wrapping the parser's reason is thrown.
Source
Thrown at hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/JMXGet.java:283
.argName("VM's connector url").hasArg()
.desc("connect to the VM on the same machine;"
+ "\n use:\n jstat -J-Djstat.showUnsupported=true -snap <vmpid> | "
+ "grep sun.management.JMXConnectorServer.address\n "
+ "to find the url").build();
opts.addOption(jmxServer);
opts.addOption(jmxHelp);
opts.addOption(jmxService);
opts.addOption(jmxPort);
opts.addOption(jmxLocalVM);
CommandLine commandLine = null;
CommandLineParser parser = new GnuParser();
try {
commandLine = parser.parse(opts, args, true);
} catch (ParseException e) {
printUsage(opts);
throw new IllegalArgumentException("invalid args: " + e.getMessage());
}
return commandLine;
}
public static void main(String[] args) {
int res = -1;
// parse arguments
Options opts = new Options();
CommandLine commandLine = null;
try {
commandLine = parseArgs(opts, args);
} catch (IllegalArgumentException iae) {
commandLine = null;
}
if (commandLine == null) {
// invalid argumentsView on GitHub (pinned to 2add963021)
Solutions
- Run 'hdfs jmxget -help' and rebuild the command with only supported options: -server, -port, -service, -localVM.
- Give every value-taking option an explicit non-empty value (e.g. -server localhost -port 8004).
- If embedding in scripts, fail early on empty variables rather than letting the parser see a dangling option.
Example fix
# before hdfs jmxget -server localhost -prot 8004 # invalid args: Unrecognized option: prot # after hdfs jmxget -server localhost -port 8004
Defensive patterns
Strategy: try-catch
Validate before calling
// Pre-validate with the same parser instead of invoking main directly
try {
CommandLine cl = new GnuParser().parse(buildJmxOptions(), args, true);
for (Option o : cl.getOptions()) {
if (o.hasArg() && (o.getValue() == null || o.getValue().isEmpty())) {
throw new IllegalArgumentException("option -" + o.getOpt() + " needs a value");
}
}
} catch (ParseException pe) {
throw new IllegalArgumentException("fix jmxget args: " + pe.getMessage(), pe);
}
JMXGet.main(args); Try / catch
try {
JMXGet.main(args);
} catch (IllegalArgumentException e) {
if (e.getMessage().startsWith("invalid args")) {
// usage was already printed; surface parser reason to caller/script
System.err.println("jmxget argument error: " + e.getMessage());
System.exit(1);
}
throw e;
} Prevention
- Always give -server/-port/-service explicit values; never pass empty shell variables.
- Run 'hdfs jmxget -help' when porting scripts between Hadoop versions to catch changed options.
When it happens
Trigger: Running 'hdfs jmxget' with a misspelled option (e.g. -prot instead of -port), an option that requires a value but is last on the line, or a stray token before recognized options depending on parse order.
Common situations: Wrong port/service combination while scraping NameNode JMX; scripts passing empty variables for -port/-service so the next token is consumed as its value; option order copied from a different Hadoop version.
Related errors
- Invalid or extra Arguments: {}
- Did not expect argument: {}
- usage: -confKey [key]
- Unknown processor {} (valid processors: xml, binary, stats)
- Illegal option {}
AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22).
Data as JSON: /api/errors/4abdae02047f981e.
Report an issue: GitHub.