Uploaded image for project: 'Grouper'
  1. Grouper
  2. GRP-5700

Code review/refactor to reduce NoSuchElementException and NullPointerException errors

    XMLWordPrintable

Details

    • Improvement
    • Resolution: Unresolved
    • Minor
    • None
    • None
    • API
    • None

    Description

      Provisioner and loader errors keep coming up because code is calling iterator().next() to get the first element of a collection, without checking for a null collection.

      Calling list.iterator().next() is risky because if the list is null, it crashes out with NoSuchElementException rather than returning null. Why not create a GrouperUtil method to get the first element of a list, and return null if the list is null? That's probably the behavior most callers would want.

      Additionally, more usage of @Nonnull and @Nullable annotations, and java.util.Optional to make objects more protected against NPEs are good practices, and are used extensively in other projects.

       

      Attachments

        Activity

          People

            chris.hyzer@at.internet2.edu Chris Hyzer (upenn.edu)
            chad.redman.3@at.internet2.edu Chad Redman
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: