pxb1988/dex2jar · error · HelpException
ERROR: Option need an argument value
Error message
ERROR: Option ${needArgOpt.getOptAndLongOpt()} need an argument value What it means
parseSetArgs supports options that require a value (hasArg=true); when such an option is the last token or is not followed by a value, needArgOpt remains set after parsing and the tool prints this ERROR and throws HelpException to show usage. It means an option that needs an argument got none.
Solutions
- Provide the required value after the option, e.g. -o out.jar
- Check the variable holding the value is non-empty in your script; quote it: "-o" "$OUT"
- Run with -h/--help to see which options take arguments
- Reorder arguments so the value directly follows its option instead of another flag
Example fix
// before OUT="" ./d2j-dex2jar.sh app.apk -o $OUT // after OUT="out.jar" ./d2j-dex2jar.sh app.apk -o "$OUT"
Defensive patterns
Strategy: validation
Validate before calling
// ensure every value-taking option is followed by a non-empty value
function checkArgs(args, needsArg) {
for (let i = 0; i < args.length; i++) {
if (needsArg.has(args[i]) && (i + 1 >= args.length || args[i+1].startsWith('-')))
throw new Error('Option ' + args[i] + ' needs a value');
}
} Try / catch
try {
tool.doMain(args);
} catch (BaseCmd.HelpException e) {
// message 'ERROR: Option X need an argument value' already printed; supply the value
} Prevention
- Always place the value immediately after its option: -o out.jar
- Check for empty/unset shell variables before building the command line
- Quote argument values: "$OUTPUT" to prevent token loss
- Remember flagless options do not exist in this parser: every @Opt with hasArg=true needs a value
When it happens
Trigger: Calling a dex2jar tool where an option like -o/--output or --thread is given without its following value, e.g. 'd2j-dex2jar.sh app.apk -o' with nothing after -o, or two options back to back where the parser expects a value ('-o --force').
Common situations: Truncating a command in scripts/shell history; shell splitting issues where the value was in an empty variable ('-o $EMPTY' expands to just '-o'); misreading boolean-style options as flagless when they actually require arguments.
Understand the failure class
Background: "no subcommand specified" and "... is required": CLI errors when a required argument is missing — this error's family across 13 libraries.
Related errors
- ERROR: Unrecognized option
- can't convert [ ] to type
- One file is required
- ERROR: Options: is required
- -cv,--class-version out of range, 1-18 is supported.
AI-assisted analysis of pxb1988/dex2jar@b5bda4fb49 (2026-09-08).
Data as JSON: /api/errors/31a3334bc28fb811.
Report an issue: GitHub.
Appendix: source
Thrown at d2j-base-cmd/src/main/java/com/googlecode/dex2jar/tools/BaseCmd.java:458
requiredOpts.remove(opt);
if (opt == null) {
System.err.println("ERROR: Unrecognized option: " + s);
throw new HelpException();
} else {
if (opt.hasArg) {
needArgOpt = opt;
} else {
opt.field.set(this, true);
}
}
} else {
remainsOptions.add(s);
}
}
if (needArgOpt != null) {
System.err.println("ERROR: Option " + needArgOpt.getOptAndLongOpt() + " need an argument value");
throw new HelpException();
}
this.remainingArgs = remainsOptions.toArray(new String[0]);
if (this.printHelp) {
throw new HelpException();
}
if (!requiredOpts.isEmpty()) {
StringBuilder sb = new StringBuilder();
sb.append("ERROR: Options: ");
boolean first = true;
for (Option option : requiredOpts) {
if (first) {
first = false;
} else {
sb.append(" and ");
}
sb.append(option.getOptAndLongOpt());
}
sb.append(" is required");View on GitHub (pinned to b5bda4fb49)