8340572: ConcurrentModificationException when sorting ArrayList sublists#21250
8340572: ConcurrentModificationException when sorting ArrayList sublists#21250szegedi wants to merge 2 commits intoopenjdk:masterfrom
Conversation
|
👋 Welcome back attila! A progress list of the required criteria for merging this PR into |
|
@szegedi 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 103 new commits pushed to the
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details. ➡️ To integrate this PR with the above commit message to the |
32c311c to
43185d7
Compare
|
@szegedi Please do not rebase or force-push to an active PR as it invalidates existing review comments. Note for future reference, the bots always squash all changes into a single commit automatically as part of the integration. See OpenJDK Developers’ Guide for more information. |
Webrevs
|
|
Just an observation, but sorting is not defined as a "structural modification" but obviously would interfere with an active iterator. So the docs may need updating to include this aspect. |
|
I am not a spcialist here. But if sorting the parent list is considered as a modification, and if the sublist is just a view of the parent list, then surely sorting/modifying the sublist should be considered as a modification of the parent list? In which case the issue here is probably deeper: SubList and parent list appear to maintain separate |
|
@dholmes-ora and @dfuch both your observations are quite valid and I agree with them. If you look at the JBS issue, we discussed this topic there. Clarifying the collections' behavior with regard to when to throw a CME, and hopefully making that behavior be consistent would be a welcome enhancement. As things stand, the scope of this fix is just ensuring that the behavior of ArrayList reverts back to what it was prior to my optimization, since the change triggered a test failure in some Google test suite. All the while recognizing that the behavior was not particularly consistent to begin with. |
|
I agree with just reverting the behaviour as discussed in JBS, but will leave the actual review for the libs folk. The more general question of when to trigger CME is a very thorny one. |
|
Right, @dholmes-ora, you might recall that we argued about this several years ago. :-) Even though I'm on the losing end of that argument, I am ok with eventually removing the modCount increments from sort and replaceAll. This is covered by JDK-8203704 which should include a spec clarification to support the change in behavior. Meanwhile, this PR should simply revert to the behavior previous to the JDK-8325679 change. (Even though that behavior is arguably wrong.) |
|
@szegedi Thanks for starting this. Just a couple comments on the test.
Thanks. |
- Add a test case for whole list sorting
|
@stuart-marks and @liach thanks, those are good suggestions – done. |
stuart-marks
left a comment
There was a problem hiding this comment.
Thanks for the updates! I've run these changes through our internal testing system and the results look good.
|
/integrate |
|
Going to push as commit 260d465.
Your commit was automatically rebased without conflicts. |
Fixes a regression with #17818 where
ArrayList.subList(…).sort()started incrementingArrayList.modCountresulting in some cases throwing aConcurrentModificationExceptionwhere none was thrown before.This change keeps the optimization from #17818 but restores the behavior where only sorting the
ArrayListchanges the mod count, but sorting its sublists does not.Progress
Issue
Reviewers
Reviewing
Using
gitCheckout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/21250/head:pull/21250$ git checkout pull/21250Update a local copy of the PR:
$ git checkout pull/21250$ git pull https://git.openjdk.org/jdk.git pull/21250/headUsing Skara CLI tools
Checkout this PR locally:
$ git pr checkout 21250View PR using the GUI difftool:
$ git pr show -t 21250Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/21250.diff
Webrev
Link to Webrev Comment