{"record":{"id":"d72e2894ea4d90b1","repo":"apache/hadoop","slug":"expecting-arguments-size-of-at-most-two-getting","errorCode":null,"errorMessage":"Expecting arguments size of at most two, getting {}","messagePattern":"Expecting arguments size of at most two, getting (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/ShellCommandFencer.java","lineNumber":146,"sourceCode":"      outPumper.join();\n    } catch (InterruptedException ie) {\n      LOG.warn(\"Interrupted while waiting for fencing command: \" + cmd);\n      return false;\n    }\n    \n    return rc == 0;\n  }\n\n  private String parseArgs(HAServiceProtocol.HAServiceState state,\n      String cmd) {\n    String[] args = cmd.split(ARG_DELIMITER);\n    if (args.length == 1) {\n      // only one command is given, assuming both src and dst\n      // will execute the same command/script.\n      return args[0];\n    }\n    if (args.length > 2) {\n      throw new IllegalArgumentException(\"Expecting arguments size of at most \"\n          + \"two, getting \" + Arrays.asList(args));\n    }\n    if (HAServiceProtocol.HAServiceState.ACTIVE.equals(state)) {\n      return args[0];\n    } else if (HAServiceProtocol.HAServiceState.STANDBY.equals(state)) {\n      return args[1];\n    } else {\n      throw new IllegalArgumentException(\n          \"Unexpected HA service state:\" + state);\n    }\n  }\n\n  /**\n   * Abbreviate a string by putting '...' in the middle of it,\n   * in an attempt to keep logs from getting too messy.\n   * @param cmd the string to abbreviate\n   * @param len maximum length to abbreviate to\n   * @return abbreviated string","sourceCodeStart":128,"sourceCodeEnd":164,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/ShellCommandFencer.java#L128-L164","documentation":"ShellCommandFencer.parseArgs() throws IllegalArgumentException('Expecting arguments size of at most two, getting [...]') when the shell fencing argument split on the ',' delimiter (ARG_DELIMITER) yields more than two segments. The two-segment form is 'commandForActiveTransition,commandForStandbyTransition' selected by the target's transition HA state; three or more parts are rejected.","triggerScenarios":"The configured shell command itself contains commas, e.g. 'shell(/bin/fence.sh a,b,c)' or an inline pipeline with commas (awk scripts, comma-separated host lists), so cmd.split(\",\") produces 3+ parts and parseArgs throws before the command ever runs.","commonSituations":"Inlining awk/sed/grep pipelines that contain commas instead of putting them in a script file; specifying active/standby command variants plus one extra comma-separated token; note this is an unchecked IllegalArgumentException (not BadFencingConfigurationException) and surfaces at tryFence time.","solutions":["Remove commas from the command: move the logic into a script file and call it, e.g. 'shell(/opt/fence.sh)'.","Keep at most one comma, separating the active-state variant from the standby-state variant: 'shell(/opt/fence_active.sh,/opt/fence_standby.sh)'.","Check the exception's argument list ([a, b, c]) to see exactly how the string was split."],"exampleFix":"<!-- before: three comma-split segments -->\n<value>shell(/opt/fence.sh primary,standby,observer)</value>\n\n<!-- after: at most two segments (active variant, standby variant) -->\n<value>shell(/opt/fence.sh primary,/opt/fence.sh standby)</value>","handlingStrategy":"validation","validationCode":"// Mirror ShellCommandFencer's split before shipping the config\nString shellArg = argInsideParens; // from 'shell(...)'\nif (shellArg.split(\",\").length > 2) {\n  throw new IllegalStateException(\n      \"shell fencer arg splits into >2 comma segments: \" + shellArg);\n}","typeGuard":null,"tryCatchPattern":"try {\n  fencer.fence(target); // internally parses args\n} catch (IllegalArgumentException iae) {\n  if (iae.getMessage().startsWith(\"Expecting arguments size\")) {\n    // rewrite the command to remove commas (move logic into a script)\n  }\n}","preventionTips":["Never inline commands containing commas; put them in a script file and reference the script path.","If using the two-variant form, keep exactly one comma: activeVariant,standbyVariant.","Unit-test the fencing config string with the same split rule (',') before deployment."],"tags":["hadoop","configuration","fencing","shell","argument-validation"],"backgroundTag":"argument-validation-failed","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}