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


The following commit(s) were added to refs/heads/master by this push:
     new 9e5a15883 [COMPRESS-677] ZipArchiveOutputStream.setEncoding(String) 
with a null value throws IllegalArgumentException
9e5a15883 is described below

commit 9e5a15883ee6b7990c00d8a85e8287221c5d51d7
Author: Gary Gregory <garydgreg...@gmail.com>
AuthorDate: Thu Apr 25 09:45:29 2024 -0400

    [COMPRESS-677] ZipArchiveOutputStream.setEncoding(String) with a null
    value throws IllegalArgumentException
---
 src/changes/changes.xml                                     |  1 +
 .../compress/archivers/zip/ZipArchiveOutputStream.java      |  3 ++-
 .../compress/archivers/zip/ZipArchiveOutputStreamTest.java  | 13 +++++++++++++
 3 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 838db8fff..de89b463a 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -50,6 +50,7 @@ The <action> type attribute can be add,update,fix,remove.
       <action type="fix" issue="COMPRESS-674" dev="ggregory" due-to="Gren 
Elliot">Validate TarArchiveEntry checksums #500.</action>
       <action type="fix" issue="COMPRESS-676" dev="ecki" due-to="Martin 
Schneider">OSGi: Remove unresolvable dependencies in manifest and make the 
commons-io packages really optional.</action>
       <action type="fix" dev="ggregory" due-to="Gary Gregory">Avoid possible 
NullPointerException in 
org.apache.commons.compress.utils.Sets.newHashSet(E...).</action>
+      <action type="fix" issue="COMPRESS-677" dev="ggregory" due-to="Jeffrey 
Adamson, Gary Gregory">ZipArchiveOutputStream.setEncoding(String) with a null 
value throws IllegalArgumentException.</action>
       <!-- UPDATE -->
       <action type="update" dev="ggregory" due-to="Dependabot, Gary 
Gregory">Bump org.apache.commons:commons-parent from 66 to 69 #495, 
#508.</action>
       <action type="update" dev="ggregory" due-to="Dependabot, Gary 
Gregory">Bump org.ow2.asm:asm from 9.6 to 9.7 #504.</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 89948f7be..488b3d8ca 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
@@ -38,6 +38,7 @@ import java.util.zip.ZipException;
 import org.apache.commons.compress.archivers.ArchiveEntry;
 import org.apache.commons.compress.archivers.ArchiveOutputStream;
 import org.apache.commons.compress.utils.ByteUtils;
+import org.apache.commons.io.Charsets;
 
 /**
  * Reimplementation of {@link java.util.zip.ZipOutputStream 
java.util.zip.ZipOutputStream} to handle the extended functionality of this 
package, especially
@@ -1337,7 +1338,7 @@ public class ZipArchiveOutputStream extends 
ArchiveOutputStream<ZipArchiveEntry>
      * @param encoding the encoding to use for file names, use null for the 
platform's default encoding
      */
     public void setEncoding(final String encoding) {
-        setEncoding(Charset.forName(encoding));
+        setEncoding(Charsets.toCharset(encoding));
     }
 
     /**
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 a60e3a8be..9bba9c0f9 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
@@ -16,11 +16,14 @@
  */
 package org.apache.commons.compress.archivers.zip;
 
+import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertFalse;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
+import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
 
 import org.apache.commons.compress.AbstractTempDirTest;
 import org.junit.jupiter.api.Test;
@@ -43,4 +46,14 @@ public class ZipArchiveOutputStreamTest extends 
AbstractTempDirTest {
             assertFalse(stream.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());
+        }
+    }
 }

Reply via email to