JDK-8308694 : Clarify reversed() default methods' implementation requirements
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util:collections
  • Affected Version: 21
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2023-05-23
  • Updated: 2023-07-20
  • Resolved: 2023-07-12
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 21 JDK 22
21Fixed 22 b07Fixed
Related Reports
Blocks :  
CSR :  
Description
https://download.java.net/java/early_access/jdk21/docs/api/java.base/java/util/Deque.html#reversed()
"Implementation Requirements:
The implementation in this interface returns an instance of a reverse-ordered Deque that delegates its operations to this Deque."

The phrase - "delegates its operations to this Deque."  one might interpret this the delegation is 'x' to 'x' ( reversedeque.addFirst() ---> deque.addFirst() )
Actual delegation is -> reversedeque.addFirst() ---> deque.addLast()

====
Similar case for  - https://download.java.net/java/early_access/jdk21/docs/api/java.base/java/util/SortedMap.html#reversed()

Similar case for  - https://download.java.net/java/early_access/jdk21/docs/api/java.base/java/util/SortedSet.html#reversed()

Do we need to clarify the spec here?
Comments
A pull request was submitted for review. URL: https://git.openjdk.org/jdk21/pull/115 Date: 2023-07-12 18:21:29 +0000
12-07-2023

Changeset: f82c8184 Author: Stuart Marks <smarks@openjdk.org> Date: 2023-07-12 16:10:41 +0000 URL: https://git.openjdk.org/jdk/commit/f82c8184b26142da4018ae096cfa39d87a4c6540
12-07-2023

A pull request was submitted for review. URL: https://git.openjdk.org/jdk/pull/14504 Date: 2023-06-15 22:38:43 +0000
15-06-2023

Similar cases of this wording for the default reversed() implSpec occur in Deque, List, SortedMap, and SortedSet. Note however that the main specification of the reversed() method says "The encounter order of elements in the returned view is the inverse of the encounter order of elements in this collection. The reverse ordering affects all order-sensitive operations, including those on the view collections of the returned view." I think the implication is fairly clear that the reverse-ordered view delegates each of its operations to the corresponding inverse-ordered operation of this collection. I don't think there is any other reasonable interpretation. It would probably be good to be more explicit in all of these cases, so I'll go ahead and update the specification. I don't think that should block continued test development though.
13-06-2023

[~smarks] Thank you. As mentioned it would be clear to state explicitly that - "reverse-ordered view delegates each of its operations to the corresponding inverse-ordered operation of this collection.
31-05-2023