Integrated: 8313739: ZipOutputStream.close() should always close the wrapped stream
Eirik Bjørsnøs
eirbjo at openjdk.org
Fri Feb 2 20:23:08 UTC 2024
On Mon, 1 Jan 2024 16:12:13 GMT, Eirik Bjørsnøs <eirbjo at openjdk.org> wrote:
> Please consider this PR which makes `DeflaterOutputStream.close()` always close its wrapped output stream exactly once.
>
> Currently, closing of the wrapped output stream happens outside the finally block where `finish()` is called. If `finish()` throws, this means the wrapped stream will not be closed. This can potentially lead to leaking resources such as file descriptors or sockets.
>
> This fix is to move the closing of the wrapped stream inside the finally block.
>
> Additionally, the `closed = true;` statement is moved to the start of the close method. This makes sure we only ever close the wrapped stream once (this aligns with the overridden method `FilterOutputStream.close´)
>
> Specification: This change brings the implementation of `DeflaterOutputStream.close()` in line with its specification: *Writes remaining compressed data to the output stream and closes the underlying stream.*
>
> Risk: This is a behavioural change. There is a small risk that existing code depends on the close method not following its specification.
>
> Testing: The PR adds a new JUnit 5 test `CloseWrappedStream.java` which simulates the failure condition and verifies that the wrapped stream was closed under failing and non-failing conditions.
This pull request has now been integrated.
Changeset: f613e133
Author: Eirik Bjørsnøs <eirbjo at openjdk.org>
URL: https://git.openjdk.org/jdk/commit/f613e13397c7890bdc9fcfb068531b3aa03ce122
Stats: 283 lines in 2 files changed: 279 ins; 2 del; 2 mod
8313739: ZipOutputStream.close() should always close the wrapped stream
Reviewed-by: jpai, lancea
-------------
PR: https://git.openjdk.org/jdk/pull/17209
More information about the core-libs-dev
mailing list