-
Notifications
You must be signed in to change notification settings - Fork 6.2k
8358015: Fix SequencedMap sequenced view method specifications #25515
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
8358015: Fix SequencedMap sequenced view method specifications #25515
Conversation
…riting default methods from SequencedCollection.
|
/csr |
|
👋 Welcome back smarks! A progress list of the required criteria for merging this PR into |
|
@stuart-marks This change now passes all automated pre-integration checks. ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details. After integration, the commit message for the final commit will be: You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been no new commits pushed to the ➡️ To integrate this PR with the above commit message to the |
|
@stuart-marks has indicated that a compatibility and specification (CSR) request is needed for this pull request. @stuart-marks please create a CSR request for issue JDK-8358015 with the correct fix version. This pull request cannot be integrated until the CSR request is approved. |
|
@stuart-marks The following label will be automatically applied to this pull request:
When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command. |
Webrevs
|
| /* non-public */ abstract static class ViewCollection<E> implements Collection<E> { | ||
| UnsupportedOperationException uoe() { return new UnsupportedOperationException(); } | ||
| // convert null entry return values into NSEE | ||
| <T> T nsee(T entry) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method can be static:
| <T> T nsee(T entry) { | |
| static <T> T nsee(T entry) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Huh, unqualified call to inherited static method. I guess that's ok.
| /* non-public */ abstract static class ViewCollection<E> implements Collection<E> { | ||
| UnsupportedOperationException uoe() { return new UnsupportedOperationException(); } | ||
| // convert null entry return values into NSEE | ||
| <T> T nsee(T entry) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| <T> T nsee(T entry) { | |
| <T extends Map.Entry<?, ?>> T nsee(T entry) { |
So we don't accidentally use this on map keys or values.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reasonable.
| * SequencedSet#addLast addLast} methods throw {@link UnsupportedOperationException}. | ||
| * Its {@link SequencedSet#getFirst getFirst} and {@link SequencedSet#getLast getLast} | ||
| * methods are implemented in terms of the {@link #firstEntry firstEntry} and {@link | ||
| * #lastEntry lastEntry} methods of this class, respectively. Its {@link |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello Stuart, some parts of this and other updated method docs use "this interface", "this map", "this class". Was it intentional to use "this class" in this newly added text?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. The other @implSpec clauses here all say "this interface" so I'll change the newly added "this class" to "this interface" in order to try to avoid confusion.
jaikiran
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall this looks good to me. I just have a small question about the newly introduced text.
The copyright years on BasicMap.java and SequencedMap.java will need a update before integrating.
I just realized one other thing - the updated BasicMap.java fixes an issue in an existing test. Do we already have tests that might cover the new proposed semantics of these methods on the returned Set/Collection from the |
Good question. There are several existing tests in BasicMap.java; see checkKeySet, checkValues, and checkEntrySet. There is also a set of tests starting at testKeySetRemoves and following which test removals on several variations of the map views, and also other mutator methods. I don't see anything obvious missing, but that doesn't mean everything is actually tested! Probably at some point it would be good to do a comprehensive analysis of the collections tests and see if they can be unified. We should probably take a look at the test coverage report too. But this is all about functional testing, in the sense of: starting from this state and performing this operation, do we get the right results and side effects? (This is mostly state verification.) The stuff in The terms state verification and behavior verification come from here: |
jaikiran
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello Stuart, thank you for the updates. These look good to me.
As for the testing, you are right that behaviour testing where method A calls B and such isn't usually tested in the JDK. I think that's fine. I was unclear about what testing I was talking about in my previous comment. I was mostly curious whether we had tests to verify that the getFirst()/getLast() EntrySet returned through a SequencedMap.sequencedEntrySet() does indeed prevent a setValue() call.
I had a look at the existing BasicMap.java and it does appear that we already have tests to verify that behaviour (the method checkUnmodifiableEntry()). So I think this change has the necessary test coverage.
| public int hashCode() { | ||
| return view().hashCode(); | ||
| } | ||
| public void addFirst(K k) { throw new UnsupportedOperationException(); } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any utility in adding @Override annotations to the methods to document intent?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The @Override annotation has been inconsistently applied in the collections implementations. In practice since so many methods are overridden, and some test would likely fail if a method weren't overridden properly, the annotation would mostly add clutter. Indeed I'm considering pulling out all uses of @Override in certain areas because they're just clutter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be helpful in situations like this to have the inverse annotation -- "All methods should be overridden, except the ones marked @NoOverride".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting. This @NoOverride idea could be useful on a subclass that wants to make sure it overrides everything. (Maybe @NoInherit would be a better name.) Meanwhile for JDK-8357272 (PR #25478) we're implementing similar policy checking in a test, though the exact policy is "no inheritance of default methods."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
@Overrideannotation has been inconsistently applied in the collections implementations. In practice since so many methods are overridden, and some test would likely fail if a method weren't overridden properly, the annotation would mostly add clutter. Indeed I'm considering pulling out all uses of@Overridein certain areas because they're just clutter.
The @OverRide annotation was one of Java's best innovations to detect consequences of changes in a base class for derived classes at compile time and it also carries information to any developer looking at a method, so calling it clutter (in Collection implementations) seems like a bit of exaggeration to me. Some IDEs have a feature to automatically add @OverRide annotations on save, and I think the JDK would improve if missing @OverRide annotations would be added to the whole code base.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The @Override annotation doesn't help with the main maintenance issue facing the collections framework, which occurs when an overriding method is missing. Virtually all of the public methods in the collection implementation classes are overrides. Adding an @Override annotation to every one of these would add a considerable amount of clutter for little benefit.
|
/integrate |
|
Going to push as commit ef47635.
Your commit was automatically rebased without conflicts. |
|
@stuart-marks Pushed as commit ef47635. 💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored. |
For a full explanation, see the bug report JDK-8358015.
This PR includes three related changes:
@implSpecclauses to reflect this behavior (which was previously ill-specified).Progress
Issues
Reviewers
Reviewing
Using
gitCheckout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/25515/head:pull/25515$ git checkout pull/25515Update a local copy of the PR:
$ git checkout pull/25515$ git pull https://git.openjdk.org/jdk.git pull/25515/headUsing Skara CLI tools
Checkout this PR locally:
$ git pr checkout 25515View PR using the GUI difftool:
$ git pr show -t 25515Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/25515.diff
Using Webrev
Link to Webrev Comment