On Tue, 12 Oct 2021 13:28:21 GMT, Ravi Reddy <rre...@openjdk.org> wrote:

>> Hi all,
>> 
>> Please review this fix for Infinite loop in ZipOutputStream.close().
>> The main issue here is when ever there is an exception during close 
>> operations on GZip we are not setting the deflator to a finished state which 
>> is leading to an infinite loop when we try writing on the same GZip 
>> instance( since we use while(!def.finished()) inside the write operation).
>> 
>> Thanks,
>> Ravi
>
> Ravi Reddy has updated the pull request incrementally with one additional 
> commit since the last revision:
> 
>   8193682 : Infinite loop in ZipOutputStream.close()

src/java.base/share/classes/java/util/zip/DeflaterOutputStream.java line 252:

> 250:         int len = def.deflate(buf, 0, buf.length);
> 251:         if (len > 0) {
> 252:             try {

Shouldn't this use try with resources:
try (out) { ...

src/java.base/share/classes/java/util/zip/DeflaterOutputStream.java line 254:

> 252:             try {
> 253:                 out.write(buf, 0, len);
> 254:             } catch (Exception e) {

Shouldn't this be a finally block?

src/java.base/share/classes/java/util/zip/DeflaterOutputStream.java line 256:

> 254:             } catch (Exception e) {
> 255:                 def.end();
> 256:                 out.close();

out.close not needed with try with resources.

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

PR: https://git.openjdk.java.net/jdk/pull/5522

Reply via email to