RFR: 8371164: ArrayList.addAll() optimizations [v5]
jengebr
duke at openjdk.org
Fri Nov 14 15:25:14 UTC 2025
On Fri, 14 Nov 2025 00:42:55 GMT, Stuart Marks <smarks at openjdk.org> wrote:
>> I'm curious, why not .equals() when we know the input is a List? That is a stricter assertion because it ensures ordering remains unchanged.
>>
>> Happy to make the change, though.
>
> The testCollection1() method gets called with a bunch of different collections, including a HashSet, which arrives at this code in the `c` parameter. When `c` is copied into a new ArrayList, it gets whatever order is presented by `c`, which is unspecified when `c` is a HashSet. The resulting order might differ from the order in the source list, and equals() over Lists compares order, so it might result in a spurious failure.
>
> I note that creating a HashSet of capacity 8 and adding 42 and then 99 results in [42, 99] but doing the same with a HashSet of capacity 16 results in [99, 42]. The test might actually pass, but if it does, it seems like it's pretty brittle.
>
> EDIT: oh, looks like the latest change renders this issue moot. But that was the issue behind my comment.
Thank you!
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/28116#discussion_r2527884895
More information about the core-libs-dev
mailing list