RFR: 8340572: ConcurrentModificationException when sorting ArrayList sublists
Stuart Marks
smarks at openjdk.org
Tue Oct 1 03:28:34 UTC 2024
On Mon, 30 Sep 2024 19:44:05 GMT, Attila Szegedi <attila at openjdk.org> wrote:
>> 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.
>
> @dholmes-ora and @dfuch both your observations are quite valid and I agree with them. If you look at the [JBS issue](https://bugs.openjdk.org/browse/JDK-8340572), 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.
@szegedi Thanks for starting this. Just a couple comments on the test.
1. It would be good to have a test case that verifies that sorting the entire list **does** increment modcount, in addition to the existing test case that tests that sorting a sublist **does not** increment modcount. (As before, this is arguably not the correct behavior, but it's the behavior that the system exhibited prior to JDK-8325679.)
2. It would be good for the test to have a more descriptive name than just the bug ID. Something like SortingModCount or similar would be fine.
Thanks.
-------------
PR Comment: https://git.openjdk.org/jdk/pull/21250#issuecomment-2384705769
More information about the core-libs-dev
mailing list