{"record":{"id":"540fb7b93573ea2c","repo":"apache/hadoop","slug":"usage-confkey-key","errorCode":null,"errorMessage":"usage: -confKey [key]","messagePattern":"usage: -confKey \\[key\\]","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":261,"sourceCode":"      List<ConfiguredNNAddress> cnnlist = DFSUtil.flattenAddressMap(\n          DFSUtil.getNNServiceRpcAddressesForCluster(config));\n      if (!cnnlist.isEmpty()) {\n        for (ConfiguredNNAddress cnn : cnnlist) {\n          InetSocketAddress rpc = cnn.getAddress();\n          tool.printOut(rpc.getHostName()+\":\"+rpc.getPort());\n        }\n        return 0;\n      }\n      tool.printError(\"Did not get namenode service rpc addresses.\");\n      return -1;\n    }\n  }\n  \n  static class PrintConfKeyCommandHandler extends CommandHandler {\n    @Override\n    protected void checkArgs(String[] args) {\n      if (args.length != 1) {\n        throw new HadoopIllegalArgumentException(\n            \"usage: \" + Command.CONFKEY.getUsage());\n      }\n    }\n\n    @Override\n    int doWorkInternal(GetConf tool, String[] args) throws Exception {\n      this.key = args[0];\n      return super.doWorkInternal(tool, args);\n    }\n  }\n  \n  private final PrintStream out; // Stream for printing command output\n  private final PrintStream err; // Stream for printing error\n\n  GetConf(Configuration conf) {\n    this(conf, System.out, System.err);\n  }\n","sourceCodeStart":243,"sourceCodeEnd":279,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/GetConf.java#L243-L279","documentation":"The -confKey mode of 'hdfs getconf' is handled by PrintConfKeyCommandHandler, whose checkArgs demands exactly one positional argument: the configuration key to print. Zero arguments or more than one triggers this HadoopIllegalArgumentException whose text is the mode's usage line ('usage: -confKey [key]').","triggerScenarios":"Running 'hdfs getconf -confKey' with no key, or 'hdfs getconf -confKey key1 key2' expecting several values at once.","commonSituations":"Script loops building the command when the key variable is empty; users trying to pass a comma-separated key list; trailing whitespace tokens parsed as extra args.","solutions":["Pass exactly one key: 'hdfs getconf -confKey dfs.replication'.","For multiple keys, call getconf once per key in a loop.","Guard scripts: skip or fail early when the key variable is unbound instead of running the bare command."],"exampleFix":"# before\nhdfs getconf -confKey\n# usage: -confKey [key]\n\n# after\nhdfs getconf -confKey dfs.replication","handlingStrategy":"validation","validationCode":"if (key == null || key.trim().isEmpty() || key.contains(\" \")) {\n  throw new IllegalArgumentException(\n      \"-confKey needs exactly one non-empty configuration key\");\n}\nToolRunner.run(new GetConf(), new String[]{\"-confKey\", key});","typeGuard":null,"tryCatchPattern":"try {\n  return ToolRunner.run(new GetConf(), argv);\n} catch (Exception e) {\n  if (e.getMessage() != null && e.getMessage().startsWith(\"usage: -confKey\")) {\n    return 2; // signal usage error distinctly in scripts\n  }\n  throw e;\n}","preventionTips":["Loop one key per invocation when reading several properties.","Fail fast on empty key variables in automation instead of executing the bare command."],"tags":["hadoop","hdfs","getconf","cli","arguments"],"backgroundTag":"missing-required-argument","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}