Uploaded image for project: 'Commons CLI'
  1. Commons CLI
  2. CLI-317

NullPointerException thrown by CommandLineParser.parse()

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Critical
    • Resolution: Fixed
    • 1.5.0
    • 1.6.0
    • Parser

    Description

      1. First at all, your testAmbiguousLongWithoutEqualSingleDash does not lead to a AmbiguousOptionException
      1. For this same test, if I replace the deprecated OptionBuilder with Option.Builder as follows
        options.addOption(Option.builder().option("f").longOpt("foo").optionalArg(true).build());
        options.addOption(Option.builder().option("b").longOpt("bar").optionalArg(false).build());
        

        the test leads to a NPE

        java.lang.NullPointerException
        	at xx.DefaultParser.handleShortAndLongOption(DefaultParser.java:476)
        	at xx.DefaultParser.handleToken(DefaultParser.java:535)
        	at xx.DefaultParser.parse(DefaultParser.java:714)
        	at xx.DefaultParser.parse(DefaultParser.java:677)
        	at xx.DefaultParser.parse(DefaultParser.java:654)
        

      Note  : tested with Github code (January 22, 2023)

      Attachments

        Activity

          People

            Unassigned Unassigned
            PhBastiani Philippe Bastiani
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: