Commons CLI
  1. Commons CLI
  2. CLI-131

Options class returns options in random order

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 1.0, 1.1
    • Fix Version/s: 1.1
    • Component/s: CLI-1.x
    • Labels:
      None

      Description

      The help formatter auto usage returns the options in a somewhat random order. This is because the options are inserted in a HashMap, and then a copy of the collection is returned with the getOptions() method.

      The getOptions method should return the options in the order they were added, or in a sorted order.

      1. bug131.patch
        3 kB
        Brian Egge
      2. bug131b.patch
        1 kB
        Brian Egge

        Issue Links

          Activity

          Hide
          Brian Egge added a comment -

          Changed the HashMaps to LinkedHashMaps will preserve the insertion order. Fix and test case attached.

          Show
          Brian Egge added a comment - Changed the HashMaps to LinkedHashMaps will preserve the insertion order. Fix and test case attached.
          Hide
          Henri Yandell added a comment -

          The usual JDK version worries. Can't remember if we're meant to be supporting 1.2 and 1.3. Personally; I vote 1.4.

          Sounds like a good improvement to me otherwise.

          Show
          Henri Yandell added a comment - The usual JDK version worries. Can't remember if we're meant to be supporting 1.2 and 1.3. Personally; I vote 1.4. Sounds like a good improvement to me otherwise.
          Hide
          Henri Yandell added a comment -

          Under 1.3, you get the following error.

          [junit] Exception in thread "main" java.lang.NoClassDefFoundError: org/w3c/dom/Node

          Which is a bit odd as I have xml-apis.jar in my ANT_HOME.

          Show
          Henri Yandell added a comment - Under 1.3, you get the following error. [junit] Exception in thread "main" java.lang.NoClassDefFoundError: org/w3c/dom/Node Which is a bit odd as I have xml-apis.jar in my ANT_HOME.
          Hide
          Brian Egge added a comment -

          CheckStyle uses the commons-cli and still supports Java 1.3, so I may need to have a think about this fix.

          Show
          Brian Egge added a comment - CheckStyle uses the commons-cli and still supports Java 1.3, so I may need to have a think about this fix.
          Hide
          Brian Egge added a comment -

          Fix the issue by sorting the options inside the HelpFormatter class. This fix would be the least likely to cause problems with existing usage.

          Another option would be to have the Options class use TreeMaps instead of HashMaps.

          Show
          Brian Egge added a comment - Fix the issue by sorting the options inside the HelpFormatter class. This fix would be the least likely to cause problems with existing usage. Another option would be to have the Options class use TreeMaps instead of HashMaps.
          Hide
          Brian Egge added a comment -

          Fix two test cases which broke because of the change in ordering.

          Show
          Brian Egge added a comment - Fix two test cases which broke because of the change in ordering.
          Hide
          Henri Yandell added a comment -

          Patches applied. Thanks Brian

          I moved the HelpFormatterTest stuff into TestHelpFormatter. I'll rename that file to the more logical HelpFormatterTest in a moment.

          Show
          Henri Yandell added a comment - Patches applied. Thanks Brian I moved the HelpFormatterTest stuff into TestHelpFormatter. I'll rename that file to the more logical HelpFormatterTest in a moment.
          Hide
          Henri Yandell added a comment -

          Rename done.

          Show
          Henri Yandell added a comment - Rename done.

            People

            • Assignee:
              Unassigned
              Reporter:
              Brian Egge
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development