RFR: 8376403: Avoid loading ArrayDeque in java.util.zip.ZipFile [v4]
Eirik Bjørsnøs
eirbjo at openjdk.org
Sat Feb 21 16:48:13 UTC 2026
On Sat, 21 Feb 2026 16:15:56 GMT, Viktor Klang <vklang at openjdk.org> wrote:
>> Eirik Bjørsnøs has updated the pull request incrementally with three additional commits since the last revision:
>>
>> - Add code comment about returning the most recently used Inflater from the cache
>> - Replace polling-style iteration with simple for loop
>> - Using add instead of addLast seems more natural for a List
>
> src/java.base/share/classes/java/util/zip/ZipFile.java line 754:
>
>> 752: // no need to double-check as only one thread gets a
>> 753: // chance to execute run() (Cleaner guarantee)...
>> 754: for (Inflater inf : inflaters) {
>
> There's an important difference between the previous version and the proposed change—poll removes elements whereas forEach just traverses the collection. Is this change intended and for what reason?
The change to use a simple loop was suggested by Jaikiran, see [#discussion_r2832992318.](https://github.com/openjdk/jdk/pull/29430#discussion_r2832992318)
The rationale was that ordering does not matter when ending inflaters and that the reference is set to null immediately after.
Setting a synchronized field to null is a bit of a code smell, so ideally I think that `inflaterCache` should be made final, the list should be cleared instead of nulled and we should introduce a separate `boolean` field to track the closed state of the cache. But that's perhaps for another PR.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/29430#discussion_r2836348971
More information about the core-libs-dev
mailing list