{"record":{"id":"636cebf8f09c2d94","repo":"apache/hadoop","slug":"unexpected-argument-args-nextargindex","errorCode":null,"errorMessage":"\"Unexpected argument \" + args[nextArgIndex]","messagePattern":"\"Unexpected argument \" \\+ args\\[nextArgIndex\\]","errorType":"validation","errorClass":"HadoopIllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/log/LogLevel.java","lineNumber":155,"sourceCode":"          \"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 {\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 {","sourceCodeStart":137,"sourceCodeEnd":173,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/log/LogLevel.java#L137-L173","documentation":"While parsing arguments, LogLevel.CLI throws HadoopIllegalArgumentException for any token that is not one of the recognized flags -getlevel, -setlevel, or -protocol. The offending token is included in the message. This is strict prefix parsing: the very first unrecognized word aborts the whole command before any request is sent.","triggerScenarios":"Typo'd flags (e.g. 'getlevel' without the leading dash, '-getlevels', '-setniveau'); pasting extra positional words before the flags; leftover shell tokens (like a stray option from a copy-pasted command) reaching the parser.","commonSituations":"Transcribing commands from documentation and losing the dash; locale keyboards producing a different hyphen character; scripts appending debug flags in the wrong position (note: generic options like -D are consumed by GenericOptionsParser only at the front).","solutions":["Correct the flag spelling — only -getlevel, -setlevel, and -protocol are accepted.","Remove stray tokens before the flags; put generic options (e.g. -Dkey=value) at the front of the command where the framework handles them.","Re-run with the exact usage shape: hadoop loglevel -getlevel <host:port> <classname> [-protocol (http|https)]."],"exampleFix":"# before\nhadoop loglevel getlevel namenode:9870 org.apache.hadoop.ipc.Server\n\n# after\nhadoop loglevel -getlevel namenode:9870 org.apache.hadoop.ipc.Server","handlingStrategy":"validation","validationCode":"Set<String> valid = Set.of(\"-getlevel\", \"-setlevel\", \"-protocol\");\nfor (String a : args) {\n  if (a.startsWith(\"-\") && !valid.contains(a)) {\n    throw new HadoopIllegalArgumentException(\"Unknown flag \" + a + \"; valid: \" + valid);\n  }\n}\nToolRunner.run(new LogLevel.CLI(conf), args);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use exactly the three documented flags, with the leading dash.","Put generic options (-D etc.) at the very front of the command where the framework consumes them.","Copy commands verbatim from 'hadoop loglevel' usage output rather than retyping."],"tags":["hadoop","logging","cli","loglevel","usage","arguments"],"backgroundTag":"invalid-cli-usage","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}