JDK 22 |
---|
22 b10Fixed |
CSR :
|
|
Duplicate :
|
|
Duplicate :
|
|
Relates :
|
|
Relates :
|
|
Relates :
|
In order to reduce interface proliferation, some of the methods on the collection interfaces are designated as optional operations. Most of these are mutator methods. Unfortunately, some of the mutator methods that were added recently, most notably the default methods added in Java 8, are not specified to be optional. In fact, they are optional, and they'll throw UnsupportedOperationException when called on an unmodifiable collection. Strictly speaking, then, this is a violation of the specification. The specifications of such methods should be modified to say that they are optional operations, and UnsupportedOperationException should be specified to be thrown if the implementing collection doesn't support that operation. The list of methods that need to be updated is as follows: Collection.removeIf List.replaceAll List.sort NavigableSet.pollFirst NavigableSet.pollLast Map.compute Map.computeIfAbsent Map.computeIfPresent Map.merge Map.putIfAbsent Map.remove (2-arg) Map.replace (2-arg) Map.replace (3-arg) Map.replaceAll NavigableMap.pollFirstEntry NavigableMap.pollLastEntry Most cases simply need "(optional operation)" to be added to the end of the leading sentence fragment in the specification. In a few cases, the doc for UnsupportedOperationException should be augmented to allow UOE to be thrown if the implementation doesn't support the operation in general. Navigable{Map,Set}.poll* need the most work.
|