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 ba58ca98b62be6e20e0de7bae4d4e98c08aea999
Author: Gary Gregory <[email protected]>
AuthorDate: Mon Aug 10 18:17:24 2026 -0400

    TarArchiveInputStream now throws ArchiveException instead of
    IllegalArgumentException.
---
 src/changes/changes.xml                                        |  5 +++--
 .../commons/compress/archivers/tar/TarArchiveInputStream.java  | 10 ++++------
 .../compress/archivers/tar/TarArchiveInputStreamTest.java      |  2 +-
 3 files changed, 8 insertions(+), 9 deletions(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index dc99f81ce..328054d3a 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -92,7 +92,7 @@ The <action> type attribute can be add,update,fix,remove.
       <action type="fix" dev="ggregory" due-to="KALI 834X, Gary 
Gregory">Reject negative ZIP64 offsets in positionAtCentralDirectory64 
(#794).</action>
       <!-- FIX TAR -->
       <action type="fix" dev="pkarwasz" due-to="Tyler Nighswander, Piotr P. 
Karwasz, Gary Gregory">>Uniform handling of special tar records in TarFile and 
TarArchiveInputStream.</action>
-      <action type="fix" dev="ggregory" due-to="Gary Gregory, Stanislav 
Fort">TarArchiveOutputStream now throws a IllegalArgumentException instead of 
an OutOfMemoryError.</action>
+      <action type="fix" dev="ggregory" due-to="Gary Gregory, Stanislav 
Fort">TarArchiveOutputStream now throws a ArchiveException instead of an 
OutOfMemoryError.</action>
       <action type="fix" dev="ggregory" issue="COMPRESS-707" due-to="Gary 
Gregory, Roel van Dijk">TarUtils.verifyCheckSum() throws an Exception when 
checksum could not be parsed.</action>
       <action type="fix" dev="ggregory" issue="COMPRESS-724" due-to="Ruiqi 
Dong, Gary Gregory">TarUtils.parsePAX1XSparseHeaders(InputStream, int) skips an 
extra record when sparse headers are already record-aligned.</action>
       <action type="fix" dev="ggregory" due-to="Gary Gregory, KALI 
834X">Reject tar sparse blocks larger than the entry size (#780).</action>
@@ -104,7 +104,8 @@ The <action> type attribute can be add,update,fix,remove.
       <action type="fix" dev="ggregory" due-to="Gary 
Gregory">TarArchiveEntry.setSize(long) now throw ArchiveException instead of 
IllegalArgumentException.</action>
       <action type="fix" dev="ggregory" due-to="Gary 
Gregory">TarArchiveEntry.addPaxHeader(String, String) now throws 
ArchiveException instead of IllegalArgumentException.</action>
       <action type="fix" dev="ggregory" due-to="Gary Gregory">TAR ParsingUtils 
now throws the IOException subclass CompressException.</action>
-      <action type="fix" dev="ggregory" due-to="Gary 
Gregory">TarArchiveOutputStream now throws ArchiveException instead of 
IllegalArgumentException..</action>
+      <action type="fix" dev="ggregory" due-to="Gary 
Gregory">TarArchiveOutputStream now throws ArchiveException instead of 
IllegalArgumentException.</action>
+      <action type="fix" dev="ggregory" due-to="Gary 
Gregory">TarArchiveInputStream now throws ArchiveException instead of 
IllegalArgumentException.</action>
       <!-- FIX ar -->
       <action type="fix" dev="ggregory" due-to="Gary 
Gregory">ArArchiveInputStream.readGNUStringTable(byte[], int, int) now provides 
a better exception message, wrapping the underlying exception.</action>
       <action type="fix" dev="ggregory" due-to="Gary 
Gregory">ArArchiveInputStream.read(byte[], int, int) now throws 
ArchiveException instead of ArithmeticException.</action>
diff --git 
a/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java
 
b/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java
index d01a80060..7607d5ccf 100644
--- 
a/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java
+++ 
b/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java
@@ -668,9 +668,8 @@ public int read(final byte[] buf, final int offset, final 
int numToRead) throws
         if (isAtEOF() || isDirectory()) {
             return -1;
         }
-        if (currEntry == null || currentInputStream == null) {
-            throw new IllegalStateException("No current tar entry");
-        }
+        ArchiveException.requireNonNull(currEntry, "No current tar entry (null 
currEntry)");
+        ArchiveException.requireNonNull(currentInputStream, "No current tar 
entry (null currentInputStream)");
         return currentInputStream.read(buf, offset, numToRead);
     }
 
@@ -746,9 +745,8 @@ public long skip(final long n) throws IOException {
         if (n <= 0 || isDirectory()) {
             return 0;
         }
-        if (currEntry == null || currentInputStream == null) {
-            throw new IllegalStateException("No current tar entry");
-        }
+        ArchiveException.requireNonNull(currEntry, "No current tar entry (null 
currEntry)");
+        ArchiveException.requireNonNull(currentInputStream, "No current tar 
entry (null currentInputStream)");
         // Use Apache Commons IO to skip as it handles skipping fully
         return IOUtils.skip(currentInputStream, n);
     }
diff --git 
a/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStreamTest.java
 
b/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStreamTest.java
index c293a53f6..896e31e7e 100644
--- 
a/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStreamTest.java
+++ 
b/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStreamTest.java
@@ -285,7 +285,7 @@ void testGetAndSetOfPaxEntry() throws Exception {
             assertEquals(entry, is.getCurrentEntry());
             assertNotSame(entry, is.getCurrentEntry());
             assertSame(weaselEntry, is.getCurrentEntry());
-            assertThrows(IllegalStateException.class, () -> {
+            assertThrows(ArchiveException.class, () -> {
                 is.setCurrentEntry(null);
                 is.read();
             }, "should abort because current entry is nulled");

Reply via email to