RFR: 8376403: Avoid loading ArrayDeque in java.util.zip.ZipFile [v4]

Viktor Klang vklang at openjdk.org
Sat Feb 21 16:18:13 UTC 2026


On Fri, 20 Feb 2026 12:51:12 GMT, Eirik Bjørsnøs <eirbjo at openjdk.org> wrote:

>> Hot on the heals of #29288, this PR replaces `ArrayDeque` with `ArrayList` for the Inflater cache implementation in `ZipFile.CleanableResource`.
>> 
>> With this PR, we change the order of the cache from a LIFO queue to a FIFO stack backed by ArrayList. The order seems unimportant, and has indeed been FIFO in the past when using `java.util.Vector`. Intuitively, it should be better to return the most recently used Inflater.
>> 
>> No tests updated, strict refactoring, `noreg-cleanup`.
>
> 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?

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/29430#discussion_r2836324373


More information about the core-libs-dev mailing list