Code review/refactor to reduce NoSuchElementException and NullPointerException errors

XMLWordPrintable

    • Type: Improvement
    • Resolution: Unresolved
    • Priority: Minor
    • None
    • Affects Version/s: None
    • Component/s: API
    • None

      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.

       

            Assignee:
            Chris Hyzer (upenn.edu)
            Reporter:
            Chad Redman
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: