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

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

commit 1425a03e756fe8a303596d5527a030b668497bcb
Author: Gary Gregory <[email protected]>
AuthorDate: Tue Aug 11 07:37:15 2026 -0400

    [TAR] TarArchiveOutputStream now throws ArchiveException instead of
    IllegalArgumentException.
---
 .../commons/compress/archivers/tar/TarArchiveOutputStream.java      | 6 +++---
 .../archivers/tar/TarArchiveOutputStreamLongFileModeTest.java       | 3 ++-
 .../commons/compress/archivers/tar/TarArchiveOutputStreamTest.java  | 6 +++---
 3 files changed, 8 insertions(+), 7 deletions(-)

diff --git 
a/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStream.java
 
b/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStream.java
index 8df01c701..40ca97c9c 100644
--- 
a/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStream.java
+++ 
b/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStream.java
@@ -458,7 +458,7 @@ private boolean handleLongName(final TarArchiveEntry entry, 
final String name, f
             final byte linkType, final String fieldName) throws IOException {
         // Fail-fast with less precision with LONGFILE_ERROR, instead 
allocating a potentially huge buffers.
         if (longFileMode == LONGFILE_ERROR && name.length() >= 
TarConstants.NAMELEN) {
-            throw new IllegalArgumentException(
+            throw new ArchiveException(
                     fieldName + " '" + StringUtils.truncate(name, 
TarConstants.NAMELEN) + "...' is too long ( > " + TarConstants.NAMELEN + " 
bytes)");
         }
         final ByteBuffer encodedName = zipEncoding.encode(name);
@@ -479,7 +479,7 @@ private boolean handleLongName(final TarArchiveEntry entry, 
final String name, f
                 write(0); // NUL terminator
                 closeArchiveEntry();
             } else if (longFileMode != LONGFILE_TRUNCATE) {
-                throw new IllegalArgumentException(
+                throw new ArchiveException(
                         fieldName + " '" + StringUtils.truncate(name, 
TarConstants.NAMELEN) + "...' is too long ( > " + TarConstants.NAMELEN + " 
bytes)");
             }
         }
@@ -637,7 +637,7 @@ private void transferModTime(final TarArchiveEntry from, 
final TarArchiveEntry t
     public void write(final byte[] wBuf, final int wOffset, final int 
numToWrite) throws IOException {
         IOUtils.checkFromIndexSize(wBuf, wOffset, numToWrite);
         if (!haveUnclosedEntry) {
-            throw new IllegalStateException("No current tar entry");
+            throw new ArchiveException("No current tar entry");
         }
         if (currBytes + numToWrite > currSize) {
             throw new ArchiveException("Request to write %,d bytes exceeds 
size in header of %,d bytes for entry '%s'", numToWrite, currSize, currName);
diff --git 
a/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStreamLongFileModeTest.java
 
b/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStreamLongFileModeTest.java
index 234d77fbc..c03b4a804 100644
--- 
a/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStreamLongFileModeTest.java
+++ 
b/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStreamLongFileModeTest.java
@@ -23,6 +23,7 @@
 
 import java.io.ByteArrayOutputStream;
 
+import org.apache.commons.compress.archivers.ArchiveException;
 import org.junit.jupiter.api.Test;
 
 import shaded.org.apache.commons.lang3.StringUtils;
@@ -42,7 +43,7 @@ void test() throws Exception {
         try (TarArchiveOutputStream taos = new TarArchiveOutputStream(new 
ByteArrayOutputStream())) {
             final TarArchiveEntry entry = new TarArchiveEntry(longName);
             entry.setSize(0);
-            assertThrows(IllegalArgumentException.class, () -> 
taos.putArchiveEntry(entry));
+            assertThrows(ArchiveException.class, () -> 
taos.putArchiveEntry(entry));
         }
     }
 }
diff --git 
a/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStreamTest.java
 
b/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStreamTest.java
index 3782cbef7..8116f5669 100644
--- 
a/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStreamTest.java
+++ 
b/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStreamTest.java
@@ -452,7 +452,7 @@ void testWriteLongDirectoryNameErrorMode() throws Exception 
{
                 + "01234567890123456789012345678901234567890123456789"
                 + "01234567890123456789012345678901234567890123456789/";
         // @formatter:on
-        assertThrows(IllegalArgumentException.class, () -> {
+        assertThrows(ArchiveException.class, () -> {
             final TarArchiveEntry t = new TarArchiveEntry(n);
             final ByteArrayOutputStream bos = new ByteArrayOutputStream();
             try (TarArchiveOutputStream tos = new TarArchiveOutputStream(bos, 
"ASCII")) {
@@ -532,7 +532,7 @@ void testWriteLongFileNameThrowsException() throws 
Exception {
                 + "01234567890123456789012345678901234567890123456789";
         final TarArchiveEntry t = new TarArchiveEntry(n);
         final TarArchiveOutputStream tos = new TarArchiveOutputStream(new 
ByteArrayOutputStream(), "ASCII");
-        assertThrows(IllegalArgumentException.class, () -> 
tos.putArchiveEntry(t));
+        assertThrows(ArchiveException.class, () -> tos.putArchiveEntry(t));
     }
 
     /**
@@ -571,7 +571,7 @@ void testWriteLongLinkNameErrorMode() throws Exception {
         final TarArchiveEntry entry = new TarArchiveEntry("test", 
TarConstants.LF_SYMLINK);
         entry.setLinkName(linkName);
 
-        assertThrows(RuntimeException.class, () -> {
+        assertThrows(ArchiveException.class, () -> {
             final ByteArrayOutputStream bos = new ByteArrayOutputStream();
             try (TarArchiveOutputStream tos = new TarArchiveOutputStream(bos, 
"ASCII")) {
                 tos.setLongFileMode(TarArchiveOutputStream.LONGFILE_ERROR);

Reply via email to