JDK-7042037 : Make NavigableSet's contract permit immutable implementations
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.util:collections
  • Affected Version: 6u24
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_2008
  • CPU: x86
  • Submitted: 2011-05-04
  • Updated: 2016-06-14
  • Resolved: 2016-06-14
Related Reports
Duplicate :  
Relates :  
Description
A DESCRIPTION OF THE REQUEST :
The contract for java.util.NavigableSet features two methods--pollFirst() and pollLast()--that are (a) destructive and (b) non-optional.

It is not clear from the contract of this interface whether these methods may throw UnsupportedOperationException.  Please clarify the contract, ideally to permit implementations of these methods to throw UnsupportedOperationException in accordance with all the other destructive operations of Collection interfaces (add, remove, retainAll, clear, etc.)

JUSTIFICATION :
It is currently impossible to create a NavigableSet implementation that is immutable and still honors the NavigableSet contract as written.

Comments
Will be handled as part of JDK-8159527.
14-06-2016

Yes, we should clarify the spec in this regard. Note that in Java SE 8, the following method was added to the j.u.Collections class: public static <T> NavigableSet<T> unmodifiableNavigableSet(NavigableSet<T> s) and its implementation throws UOE for the pollFirst() and pollLast() methods, among others. Similar issues apply to NavigableMap.
13-06-2016