{"record":{"id":"5e5ebc9268a6d67c","repo":"apache/hadoop","slug":"did-not-expect-argument","errorCode":null,"errorMessage":"Did not expect argument: {}","messagePattern":"Did not expect argument: (.+?)","errorType":"validation","errorClass":"HadoopIllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/GetConf.java","lineNumber":170,"sourceCode":"    \n    CommandHandler(String key) {\n      this.key = key;\n    }\n\n    final int doWork(GetConf tool, String[] args) {\n      try {\n        checkArgs(args);\n\n        return doWorkInternal(tool, args);\n      } catch (Exception e) {\n        tool.printError(e.getMessage());\n      }\n      return -1;\n    }\n\n    protected void checkArgs(String args[]) {\n      if (args.length > 0) {\n        throw new HadoopIllegalArgumentException(\n            \"Did not expect argument: \" + args[0]);\n      }\n    }\n\n    \n    /** Method to be overridden by sub classes for specific behavior */\n    int doWorkInternal(GetConf tool, String[] args) throws Exception {\n\n      String value = tool.getConf().getTrimmed(key);\n      if (value != null) {\n        tool.printOut(value);\n        return 0;\n      }\n      tool.printError(\"Configuration \" + key + \" is missing.\");\n      return -1;\n    }\n  }\n  ","sourceCodeStart":152,"sourceCodeEnd":188,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/GetConf.java#L152-L188","documentation":"'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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"# before\nhdfs getconf -namenodes ns1\n# Did not expect argument: ns1\n\n# after\nhdfs getconf -namenodes","handlingStrategy":"validation","validationCode":"// zero-operand getconf modes\nString[] positional = argsAfterOptions;\nif (positional.length > 0) {\n  throw new IllegalArgumentException(\n      \"this getconf mode takes no positional argument: \" + positional[0]);\n}\nToolRunner.run(new GetConf(), fullArgs);","typeGuard":null,"tryCatchPattern":"try {\n  return ToolRunner.run(new GetConf(conf), argv);\n} catch (Exception e) {\n  // GetConf.doWork already prints e.getMessage(); a nonzero exit means bad usage\n  System.err.println(\"getconf usage: run 'hdfs getconf' with no args to list modes\");\n  return -1;\n}","preventionTips":["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."],"tags":["hadoop","hdfs","getconf","cli","arguments"],"backgroundTag":"invalid-cli-arguments","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}