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

Missing Null pointer checks in CommandLine.java

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 1.4
    • 1.6.0
    • CLI-2.x
    • None

    Description

      • CommandLine.java #L233
        Method call to `getValuesList()` returns the possible values of `Option` for which it is called as List or returns `null`. In case it returns `null`, `addAll()` method call on type `List` with `null` as an argument will lead to a NullPointerException. This can be prevented by explicitly checking and handling the cases when it might return null. I have made changes for the same
      • CommandLine.java #L260
        As per the implementation of `stripLeadingHyphens(String)`, there exists cases when it might return `null`. And calling `equals` method on a null return value (#L263 ) will lead to null pointer exception. So as to prevent this I have made changes to explicitly return null in case `stripLeadingHyphens` returns null
      • CommandLine.java #L472  
        There is a possibility that `addOption` method is called with null as an argument. In that case we will be adding null values to our list of processed options (as `List` does not thrown any null pointer exception even if `add` method is called with null values). So as to prevent this we need to make sure that value that we are adding to list of processed option is not null.

      I have created a pull request for addressing these issues, see

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              dilraj45 Dilraj Singh
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 10m
                  10m