{"record":{"id":"64ff06739da53669","repo":"apache/hadoop","slug":"not-enough-arguments-expected-but-got","errorCode":null,"errorMessage":"Not enough arguments: expected {} but got {}","messagePattern":"Not enough arguments: expected (.+?) but got (.+?)","errorType":"exception","errorClass":"NotEnoughArgumentsException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/CommandFormat.java","lineNumber":135,"sourceCode":"        if (pos < args.size() && (args.size() > minPar)\n                && !args.get(pos).startsWith(\"-\")) {\n          arg = args.get(pos);\n          args.remove(pos);\n        } else {\n          arg = \"\";\n        }\n        if (!arg.startsWith(\"-\") || arg.equals(\"-\")) {\n          optionsWithValue.put(opt, arg);\n        }\n      } else if (ignoreUnknownOpts) {\n        pos++;\n      } else {\n        throw new UnknownOptionException(arg);\n      }\n    }\n    int psize = args.size();\n    if (psize < minPar) {\n      throw new NotEnoughArgumentsException(minPar, psize);\n    }\n    if (psize > maxPar) {\n      throw new TooManyArgumentsException(maxPar, psize);\n    }\n  }\n  \n  /** Return if the option is set or not\n   * \n   * @param option String representation of an option\n   * @return true is the option is set; false otherwise\n   */\n  public boolean getOpt(String option) {\n    return options.containsKey(option) ? options.get(option) : false;\n  }\n\n  /**\n   * get the option's value\n   *","sourceCodeStart":117,"sourceCodeEnd":153,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/CommandFormat.java#L117-L153","documentation":"Thrown by CommandFormat.parse() when, after all recognized options have been stripped from the argument list, fewer positional arguments remain than the command's declared minimum (minPar). NotEnoughArgumentsException extends IllegalArgumentException and reports 'Not enough arguments: expected <min> but got <n>'. Options with values (e.g. -t 4) also consume their value token before the count is taken, which can silently reduce the remaining count.","triggerScenarios":"'hdfs dfs -cp /src' (cp declares minPar=2, one path left), 'hadoop fs -test -e' with no path, 'hdfs dfs -appendToFile' with fewer than 2 arguments, or an option-with-value whose value token was itself the last positional argument (e.g. '-put -t dst' where 'dst' is swallowed as the -t value).","commonSituations":"Shell scripts where a variable expands to empty (e.g. 'hdfs dfs -mkdir $DIR' with unset DIR); value-options like -t/-q consuming the next token when it is not dash-prefixed; commands invoked from Java via FsShell.run() with programmatically-built argument lists that dropped an element.","solutions":["Check the command's usage ('hdfs dfs -help <cmd>') and supply the required number of positional paths","Set -u / check your shell variables before invoking FsShell so empty arguments are not silently dropped","When using value-options like -t/-q, always attach the value in the same token ('-t 4') and ensure it is not the argument you intended as a path","In code, assert args.length after option stripping before calling run()"],"exampleFix":"# before\nhdfs dfs -cp /user/me/source.csv\n# after\nhdfs dfs -cp /user/me/source.csv /user/me/destination/","handlingStrategy":"validation","validationCode":"// enforce the command's minimum positional count before invoking FsShell\nlong positional = Arrays.stream(argv).filter(a -> !a.startsWith(\"-\")).count();\nif (positional < 2) { // e.g. cp needs src + dst\n  throw new IllegalArgumentException(\"cp requires <src> ... <dst>, got \" + positional);\n}","typeGuard":null,"tryCatchPattern":"try {\n  cf.parse(args);\n} catch (CommandFormat.NotEnoughArgumentsException e) {\n  // e.getMessage() == \"Not enough arguments: expected N but got M\"\n  throw new UsageException(command.getUsage(), e);\n}","preventionTips":["Use set -u (or null checks) so empty variables fail loudly instead of vanishing from the argument list","Remember value-options like -t/-q consume the following non-dash token, which can eat a positional path","Unit-test wrapper scripts with empty-input cases"],"tags":["hadoop","hdfs","cli","argument-validation","shell","java"],"backgroundTag":"missing-required-argument","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}