RFR: 8225763: Inflater and Deflater should implement AutoCloseable [v14]

Roger Riggs rriggs at openjdk.org
Tue Jan 7 20:46:39 UTC 2025


On Tue, 7 Jan 2025 10:45:09 GMT, Jaikiran Pai <jpai at openjdk.org> wrote:

>> Can I please get a review of this enhancement which proposes to enhance `java.util.zip.Deflater/Inflater` classes to now implement `AutoCloseable`?
>> 
>> The actual work for this was done a few years back when we discussed the proposed approaches and then I raised a RFR. At that time I couldn't take this to completion. The current changes in this PR involve the implementation that was discussed at that time and also have implemented the review suggestions from that time. Here are those previous discussions and reviews:
>> 
>> https://mail.openjdk.org/pipermail/core-libs-dev/2019-June/061079.html
>> https://mail.openjdk.org/pipermail/core-libs-dev/2019-July/061177.html
>> https://mail.openjdk.org/pipermail/core-libs-dev/2019-July/061229.html
>> 
>> To summarize those discussions, we had concluded that:
>> - `Deflater` and `Inflater` will implement the `AutoCloseable` interface
>> -  In the `close()` implementation we will invoke the `end()` method (`end()` can be potentially overridden by subclasses).
>> - `close()` will be specified and implemented to be idempotent. Calling `close()` a second time or more will be a no-op.
>> - Calling `end()` and then `close()`, although uncommon, will also support idempotency and that `close()` call will be a no-op.
>> - However, calling `close()` and then `end()` will not guarantee idempotency and depending on the implementing subclass, the `end()` may throw an exception.
>> 
>> New tests have been included as part of these changes and they continue to pass along with existing tests in tier1, tier2 and tier3. When I had originally added these new tests, I hadn't used junit. I can convert them to junit if that's preferable.
>> 
>> I'll file a CSR shortly.
>
> Jaikiran Pai has updated the pull request incrementally with one additional commit since the last revision:
> 
>   change "@since" to 25

src/java.base/share/classes/java/util/zip/Deflater.java line 815:

> 813:      * than {@link Integer#MAX_VALUE}.
> 814:      *
> 815:      * @throws IllegalStateException if the Deflater is closed

@throws should follow @return;  (Style notes in https://www.oracle.com/technical-resources/articles/java/javadoc-tool.html).

src/java.base/share/classes/java/util/zip/Deflater.java line 848:

> 846:      * than {@link Integer#MAX_VALUE}.
> 847:      *
> 848:      * @throws IllegalStateException if the Deflater is closed

Ditto `@throws` throws should follow `@return`

src/java.base/share/classes/java/util/zip/Inflater.java line 663:

> 661:      * than {@link Integer#MAX_VALUE}.
> 662:      *
> 663:      * @throws IllegalStateException if the Inflater is closed

Ditto ` @throws` should follow `@return`

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

PR Review Comment: https://git.openjdk.org/jdk/pull/19675#discussion_r1906011672
PR Review Comment: https://git.openjdk.org/jdk/pull/19675#discussion_r1906012010
PR Review Comment: https://git.openjdk.org/jdk/pull/19675#discussion_r1906014988


More information about the core-libs-dev mailing list