eclipse-collections icon indicating copy to clipboard operation
eclipse-collections copied to clipboard

Fix SortedSetIterable getFirst/getLast to return null on empty sets.

Open motlin opened this issue 3 weeks ago • 0 comments

The sorted set implementations (TreeSortedSet, SortedSetAdapter, AbstractImmutableSortedSet) previously delegated getFirst() and getLast() to java.util.SortedSet's first() and last() methods, which throw NoSuchElementException when the set is empty. This violated the RichIterable/OrderedIterable contract which specifies that getFirst() and getLast() should return null for empty collections.

Changed to check isEmpty() before calling first()/last(), returning null for empty sets. Updated SortedSetIterableTestCase to remove the assertThrows tests that verified the incorrect exception behavior.

motlin avatar Dec 03 '25 20:12 motlin