{"record":{"id":"8c485efa31862840","repo":"apache/hadoop","slug":"must-specify-either-getlevel-or-setlevel","errorCode":null,"errorMessage":"Must specify either -getlevel or -setlevel","messagePattern":"Must specify either -getlevel or -setlevel","errorType":"validation","errorClass":"HadoopIllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/log/LogLevel.java","lineNumber":162,"sourceCode":"        throw new HadoopIllegalArgumentException(\"No arguments specified\");\n      }\n      int nextArgIndex = 0;\n      while (nextArgIndex < args.length) {\n        if (args[nextArgIndex].equals(\"-getlevel\")) {\n          nextArgIndex = parseGetLevelArgs(args, nextArgIndex);\n        } else if (args[nextArgIndex].equals(\"-setlevel\")) {\n          nextArgIndex = parseSetLevelArgs(args, nextArgIndex);\n        } else if (args[nextArgIndex].equals(\"-protocol\")) {\n          nextArgIndex = parseProtocolArgs(args, nextArgIndex);\n        } else {\n          throw new HadoopIllegalArgumentException(\n              \"Unexpected argument \" + args[nextArgIndex]);\n        }\n      }\n\n      // if operation is never specified in the arguments\n      if (operation == Operations.UNKNOWN) {\n        throw new HadoopIllegalArgumentException(\n            \"Must specify either -getlevel or -setlevel\");\n      }\n\n      // if protocol is unspecified, set it as http.\n      if (protocol == null) {\n        protocol = PROTOCOL_HTTP;\n      }\n    }\n\n    private int parseGetLevelArgs(String[] args, int index) throws\n        HadoopIllegalArgumentException {\n      // fail if multiple operations are specified in the arguments\n      if (operation != Operations.UNKNOWN) {\n        throw new HadoopIllegalArgumentException(\n            \"Redundant -getlevel command\");\n      }\n      // check number of arguments is sufficient\n      if (index+2 >= args.length) {","sourceCodeStart":144,"sourceCodeEnd":180,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/log/LogLevel.java#L144-L180","documentation":"After the whole argument vector parses cleanly, LogLevel.CLI verifies an operation was actually selected; if operation is still UNKNOWN it throws HadoopIllegalArgumentException. This catches inputs where every token was individually valid but none of them chose -getlevel/-setlevel — the classic case being '-protocol http' alone.","triggerScenarios":"Running 'hadoop loglevel -protocol http' (protocol given, no operation); passing only generic options that survive into the parser as no-ops; a script that assembles the command but drops the operation flag due to an empty variable.","commonSituations":"Copy-paste commands that lost their first token; scripts where the OPERATION variable is empty; users assuming the tool defaults to -getlevel when only a protocol is given.","solutions":["Add the missing operation flag: '-getlevel <host:port> <classname>' or '-setlevel <host:port> <classname> <level>'.","Fix the constructing script so the operation variable cannot expand to nothing.","Check the printed usage (run() calls printUsage on this failure) and mirror its exact shape."],"exampleFix":"# before\nhadoop loglevel -protocol https namenode:9871\n\n# after\nhadoop loglevel -getlevel namenode:9871 org.apache.hadoop.ipc.Server -protocol https","handlingStrategy":"validation","validationCode":"boolean hasOp = Arrays.stream(args).anyMatch(a -> a.equals(\"-getlevel\") || a.equals(\"-setlevel\"));\nif (!hasOp) {\n  throw new HadoopIllegalArgumentException(\"Must include -getlevel or -setlevel\");\n}\nToolRunner.run(new LogLevel.CLI(conf), args);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always include one operation flag; -protocol alone does nothing.","In scripts, verify the OPERATION variable is set before building the command.","Remember the tool defaults only the protocol (http), never the operation."],"tags":["hadoop","logging","cli","loglevel","usage"],"backgroundTag":"missing-cli-flag","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}