{"record":{"id":"e81a08750bab4269","repo":"apache/hadoop","slug":"option-requires-1-argument","errorCode":null,"errorMessage":"option {} requires 1 argument.","messagePattern":"option (.+?) requires 1 argument\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/StringUtils.java","lineNumber":1185,"sourceCode":"   *\n   * @param name  Name of the option to remove.  Example: -foo.\n   * @param args  List of arguments.\n   * @return      null if the option was not found; the value of the \n   *              option otherwise.\n   * @throws IllegalArgumentException if the option's argument is not present\n   */\n  public static String popOptionWithArgument(String name, List<String> args)\n      throws IllegalArgumentException {\n    String val = null;\n    for (Iterator<String> iter = args.iterator(); iter.hasNext(); ) {\n      String cur = iter.next();\n      if (cur.equals(\"--\")) {\n        // stop parsing arguments when you see --\n        break;\n      } else if (cur.equals(name)) {\n        iter.remove();\n        if (!iter.hasNext()) {\n          throw new IllegalArgumentException(\"option \" + name + \" requires 1 \" +\n              \"argument.\");\n        }\n        val = iter.next();\n        iter.remove();\n        break;\n      }\n    }\n    return val;\n  }\n  \n  /**\n   * From a list of command-line arguments, remove an option.\n   *\n   * @param name  Name of the option to remove.  Example: -foo.\n   * @param args  List of arguments.\n   * @return      true if the option was found and removed; false otherwise.\n   */\n  public static boolean popOption(String name, List<String> args) {","sourceCodeStart":1167,"sourceCodeEnd":1203,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/StringUtils.java#L1167-L1203","documentation":"StringUtils.popOptionWithArgument iterates the argument list looking for an exact match of the option name (stopping early at a '--' separator). When it finds the name, it removes it and consumes the next token as the option's value; if the option was the last token in the list, there is nothing to consume and it throws this IllegalArgumentException. The parser scans the whole list, so the option being last anywhere-after-a-'--' just returns null instead.","triggerScenarios":"StringUtils.popOptionWithArgument(\"--conf\", java.util.Arrays.asList(\"--conf\")); a list like [\"-v\", \"--conf\"] where --conf is final; shell scripts or Java tool drivers where the user supplied the flag but its value was swallowed by quoting bugs or dropped entirely. Note the option value itself is taken verbatim: [\"--conf\", \"--fs\"] does NOT throw — '--fs' becomes the value.","commonSituations":"Command-line tools built on StringUtils.popOptionWithArgument where the user forgot the value ('hdfs --conf'); shell quoting that eats an empty argument; scripts conditionally appending an option without its argument when a variable is empty.","solutions":["Supply the missing value token: '--conf core-site.xml'.","Pre-scan the args list: if the option name is present at the last index (and not preceded by '--'), fail with a usage message before calling popOptionWithArgument.","Catch IllegalArgumentException and print the tool's usage text naming the option.","In scripts, guard with a variable check (e.g. [ -n \"$CONF\" ] && set -- --conf \"$CONF\" \"$@\") so the option is only appended together with its value."],"exampleFix":"// before\nList<String> args = new ArrayList<>(Arrays.asList(\"--conf\"));\nString conf = StringUtils.popOptionWithArgument(\"--conf\", args);\n// throws: option --conf requires 1 argument.\n\n// after\nList<String> args = new ArrayList<>(Arrays.asList(\"--conf\", \"core-site.xml\"));\nString conf = StringUtils.popOptionWithArgument(\"--conf\", args);","handlingStrategy":"validation","validationCode":"// fail with usage text before parsing if option lacks a value token\nstatic boolean optionHasValue(List<String> args, String name) {\n  for (int i = 0; i < args.size(); i++) {\n    if (args.get(i).equals(\"--\")) return true; // parsing stops; ok\n    if (args.get(i).equals(name)) {\n      return i + 1 < args.size();\n    }\n  }\n  return true; // option absent\n}\n\nif (!optionHasValue(args, \"--conf\")) {\n  System.err.println(\"Missing value for --conf\");\n  printUsage();\n  System.exit(1);\n}\nString conf = StringUtils.popOptionWithArgument(\"--conf\", args);","typeGuard":null,"tryCatchPattern":"try {\n  conf = StringUtils.popOptionWithArgument(\"--conf\", args);\n} catch (IllegalArgumentException e) {\n  System.err.println(\"Error: \" + e.getMessage());\n  printUsage();\n  System.exit(2);\n}","preventionTips":["Always append option and value together when building arg lists programmatically.","Print usage on IllegalArgumentException from arg parsing instead of stack traces.","In shell wrappers, quote values so empty or split arguments cannot drop the value token."],"tags":["command-line-arguments","argument-parsing","hadoop-common"],"backgroundTag":"missing-command-line-argument","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}