Commons CLI
  1. Commons CLI
  2. CLI-28

[CLI] Infinite Loop in Command-Line processing

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.1
    • Component/s: CLI-1.x
    • Labels:
      None
    • Environment:

      Operating System: All
      Platform: All

      Description

      In some cases, CLI-2 hangs in an infinite loop. I've created the following Group:

      – snip –
      Option inputFormatOption = optionBuilder.withLongName("input-format")
      .create();
      Argument argument = argumentBuilder.withName("file")
      .create();
      Group children = groupBuilder.withName("options")
      .withOption(inputFormatOption)
      .create();
      Command command = commandBuilder.withName("convert")
      .withChildren(children)
      .withArgument(argument)
      .create();
      Group root = groupBuilder.withName("commands")
      .withOption(createConvertCommand())
      .create();
      – snip –

      When I use the group:
      -snip-
      Parser parser = new Parser();
      parser.setGroup(root);
      parser.parse(args);
      – snip

      and use the following command line:
      convert test.txt --input-format a

      the parser hangs in an infinite loop.

        Activity

        Hide
        Rob Oxspring added a comment -

        Good catch - sorry for the delayed response.
        I've added a new test and have fixed resolved the problem in CVS.
        One thing I wasn't so sure of though was the result you expected: the fixed
        version now throws an OptionException because the string 'a' cannot be processed
        by the Group root. If this is not what you expected then perhaps you meant to
        add an Argument to the inputFormatOption?

        Rob

        Show
        Rob Oxspring added a comment - Good catch - sorry for the delayed response. I've added a new test and have fixed resolved the problem in CVS. One thing I wasn't so sure of though was the result you expected: the fixed version now throws an OptionException because the string 'a' cannot be processed by the Group root. If this is not what you expected then perhaps you meant to add an Argument to the inputFormatOption? Rob
        Hide
        Simon Raess added a comment -

        You're right. I meant to add an argument to --input-format. So throwing an exception is the expected
        behavior.

        Show
        Simon Raess added a comment - You're right. I meant to add an argument to --input-format. So throwing an exception is the expected behavior.

          People

          • Assignee:
            Unassigned
            Reporter:
            Simon Raess
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development