{"record":{"id":"11eb60a3e2d2f96c","repo":"apache/hadoop","slug":"expect-either-getlevel-or-setlevel","errorCode":null,"errorMessage":"Expect either -getlevel or -setlevel","messagePattern":"Expect 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":136,"sourceCode":"      return 0;\n    }\n\n    /**\n     * Send HTTP/HTTPS request to the daemon.\n     * @throws HadoopIllegalArgumentException if arguments are invalid.\n     * @throws Exception if unable to connect\n     */\n    private void sendLogLevelRequest()\n        throws HadoopIllegalArgumentException, Exception {\n      switch (operation) {\n      case GETLEVEL:\n        doGetLevel();\n        break;\n      case SETLEVEL:\n        doSetLevel();\n        break;\n      default:\n        throw new HadoopIllegalArgumentException(\n          \"Expect either -getlevel or -setlevel\");\n      }\n    }\n\n    public void parseArguments(String[] args) throws\n        HadoopIllegalArgumentException {\n      if (args.length == 0) {\n        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 {","sourceCodeStart":118,"sourceCodeEnd":154,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/log/LogLevel.java#L118-L154","documentation":"LogLevel.CLI.sendLogLevelRequest dispatches on the parsed operation enum and throws HadoopIllegalArgumentException from the default branch when the operation is neither GETLEVEL nor SETLEVEL. In the stock run() flow this is a defensive duplicate of the check in parseArguments (which normally rejects such inputs first, see 'Must specify either -getlevel or -setlevel'); it fires standalone only when the internal operation state was never set before sending.","triggerScenarios":"Calling sendLogLevelRequest() programmatically without a prior successful parseArguments(); a subclass or test resetting operation state to UNKNOWN before the request is sent.","commonSituations":"Embedding or unit-testing LogLevel.CLI internals; refactors that bypass the normal run()/parseArguments path.","solutions":["Always run parseArguments(args) to completion (it sets the operation) before calling sendLogLevelRequest().","Or drive the tool the supported way — ToolRunner.run(new CLI(conf), args) / 'hadoop loglevel ...' — which enforces the argument checks for you.","If you keep programmatic use, verify operation != Operations.UNKNOWN before sending and fail with your own message."],"exampleFix":"// before\nCLI cli = new CLI(conf);\ncli.sendLogLevelRequest(); // operation still UNKNOWN\n\n// after\nCLI cli = new CLI(conf);\nToolRunner.run(cli, args); // parses args, sets operation, then sends","handlingStrategy":"validation","validationCode":"// Ensure arguments were parsed (operation set) before sending the request\nif (operation == Operations.UNKNOWN) {\n  throw new HadoopIllegalArgumentException(\n      \"No operation parsed; call parseArguments(args) with -getlevel/-setlevel first\");\n}\nsendLogLevelRequest();","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use ToolRunner.run(new CLI(conf), args) instead of driving CLI internals directly.","If embedding, always run parseArguments() successfully before sendLogLevelRequest().","Unit-test the embedded flow with empty and flag-only args to assert the operation guard fires."],"tags":["hadoop","logging","cli","loglevel","usage"],"backgroundTag":"invalid-cli-usage","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}