You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2024/12/13 23:15:05 UTC

(commons-compress) 02/02: ZipArchiveOutputStream.close() does not close its underlying output stream

This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-compress.git

commit 248b191c24c7640899af47c33f79c017f1970c87
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Fri Dec 13 18:14:57 2024 -0500

    ZipArchiveOutputStream.close() does not close its underlying output
    stream
---
 src/changes/changes.xml                             |  1 +
 .../archivers/zip/ZipArchiveOutputStream.java       |  2 +-
 .../archivers/zip/ZipArchiveOutputStreamTest.java   | 21 ++++++++++++---------
 3 files changed, 14 insertions(+), 10 deletions(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 85e1eb105..2ea89793a 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -55,6 +55,7 @@ The <action> type attribute can be add,update,fix,remove.
       <action type="fix" dev="ggregory" due-to="ddeschenes-1, Gary Gregory">Throw an IllegalArgumentException when a file name or comment in gzip parameters encodes to a byte array with a 0 byte #618.</action>
       <action type="fix" dev="ggregory" due-to="Glavo">Update outdated links in ZipMethod Javadoc #619.</action>
       <action type="fix" dev="ggregory" due-to="Gary Gregory">Deprecate ZipUtil.signedByteToUnsignedInt(byte) in favor of Byte.toUnsignedInt(byte).</action> 
+      <action type="fix" dev="ggregory" due-to="Gary Gregory">ZipArchiveOutputStream.close() does not close its underlying output stream.</action> 
       <!-- ADD -->
       <action type="add" dev="ggregory" due-to="Gary Gregory">Add GzipParameters.getModificationInstant().</action>
       <action type="add" dev="ggregory" due-to="Gary Gregory">Add GzipParameters.setModificationInstant(Instant).</action>
diff --git a/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java b/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java
index d22bbeaf0..979f174b1 100644
--- a/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java
+++ b/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java
@@ -904,7 +904,7 @@ public class ZipArchiveOutputStream extends ArchiveOutputStream<ZipArchiveEntry>
      */
     void destroy() throws IOException {
         if (out != null) {
-            out.close();
+            super.close();
         }
     }
 
diff --git a/src/test/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStreamTest.java b/src/test/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStreamTest.java
index 9bba9c0f9..28bb325f3 100644
--- a/src/test/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStreamTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStreamTest.java
@@ -35,25 +35,28 @@ public class ZipArchiveOutputStreamTest extends AbstractTempDirTest {
 
     @Test
     public void testFileBasics() throws IOException {
-        try (ZipArchiveOutputStream stream = new ZipArchiveOutputStream(createTempFile())) {
-            assertTrue(stream.isSeekable());
+        ZipArchiveOutputStream ref;
+        try (ZipArchiveOutputStream outputStream = new ZipArchiveOutputStream(createTempFile())) {
+            ref = outputStream;
+            assertTrue(outputStream.isSeekable());
         }
+        assertTrue(ref.isClosed());
     }
 
     @Test
     public void testOutputStreamBasics() throws IOException {
-        try (ZipArchiveOutputStream stream = new ZipArchiveOutputStream(new ByteArrayOutputStream())) {
-            assertFalse(stream.isSeekable());
+        try (ZipArchiveOutputStream outputStream = new ZipArchiveOutputStream(new ByteArrayOutputStream())) {
+            assertFalse(outputStream.isSeekable());
         }
     }
 
     @Test
     public void testSetEncoding() throws IOException {
-        try (ZipArchiveOutputStream stream = new ZipArchiveOutputStream(createTempFile())) {
-            stream.setEncoding(StandardCharsets.UTF_8.name());
-            assertEquals(StandardCharsets.UTF_8.name(), stream.getEncoding());
-            stream.setEncoding(null);
-            assertEquals(Charset.defaultCharset().name(), stream.getEncoding());
+        try (ZipArchiveOutputStream outputStream = new ZipArchiveOutputStream(createTempFile())) {
+            outputStream.setEncoding(StandardCharsets.UTF_8.name());
+            assertEquals(StandardCharsets.UTF_8.name(), outputStream.getEncoding());
+            outputStream.setEncoding(null);
+            assertEquals(Charset.defaultCharset().name(), outputStream.getEncoding());
         }
     }
 }