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 533a95d02dc4fa3a06c49f522536c828285dd2ff Author: Gary Gregory <[email protected]> AuthorDate: Mon Aug 10 17:41:29 2026 -0400 ArArchiveInputStream now throws ArchiveException instead of IllegalArgumentException. --- src/changes/changes.xml | 1 + .../apache/commons/compress/archivers/ar/ArArchiveInputStream.java | 7 ++----- .../commons/compress/archivers/ar/ArArchiveInputStreamTest.java | 5 +++-- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index eddf0b565..8d48cbc2f 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -108,6 +108,7 @@ The <action> type attribute can be add,update,fix,remove. <action type="fix" dev="ggregory" due-to="Gary Gregory">ArArchiveInputStream.read(byte[], int, int) now throws ArchiveException instead of ArithmeticException.</action> <action type="fix" dev="pkarwasz" due-to="Tyler Nighswander">Simplify handling of special AR records in ArArchiveInputStream.</action> <action type="fix" dev="ggregory" due-to="Gary Gregory">Most ArArchiveEntry constructors now throws the IOException subclass ArchiveException.</action> + <action type="fix" dev="ggregory" due-to="Gary Gregory">ArArchiveInputStream now throws ArchiveException instead of IllegalArgumentException.</action> <!-- FIX arj --> <action type="fix" dev="pkarwasz" due-to="Piotr P. Karwasz">Correct byte accounting and truncation errors in ARJ input stream.</action> <action type="fix" dev="pkarwasz" due-to="Piotr P. Karwasz">Add strict header validation in ARJ input stream and `selfExtracting` option.</action> diff --git a/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveInputStream.java b/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveInputStream.java index 85a85e553..76af6eb25 100644 --- a/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveInputStream.java +++ b/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveInputStream.java @@ -445,9 +445,7 @@ public int read(final byte[] b, final int off, final int len) throws IOException if (len == 0) { return 0; } - if (currentEntry == null) { - throw new IllegalStateException("No current ar entry"); - } + ArchiveException.requireNonNull(currentEntry, "No current ar entry"); final long entryEnd = entryOffset + currentEntry.getLength(); final long offset = getBytesRead(); if (len < 0 || offset >= entryEnd) { @@ -456,8 +454,7 @@ public int read(final byte[] b, final int off, final int len) throws IOException final int toRead = ArchiveException.toIntExact(Math.min(len, entryEnd - offset)); final int ret = in.read(b, off, toRead); if (ret < 0) { - throw new EOFException(String.format( - "Premature end of ar archive: Entry '%s' is truncated or incomplete.", currentEntry.getName())); + throw new EOFException(String.format("Premature end of ar archive: Entry '%s' is truncated or incomplete.", currentEntry.getName())); } count(ret); return ret; diff --git a/src/test/java/org/apache/commons/compress/archivers/ar/ArArchiveInputStreamTest.java b/src/test/java/org/apache/commons/compress/archivers/ar/ArArchiveInputStreamTest.java index 46345b782..f98ee3a0e 100644 --- a/src/test/java/org/apache/commons/compress/archivers/ar/ArArchiveInputStreamTest.java +++ b/src/test/java/org/apache/commons/compress/archivers/ar/ArArchiveInputStreamTest.java @@ -32,6 +32,7 @@ import org.apache.commons.compress.AbstractTest; import org.apache.commons.compress.archivers.ArchiveEntry; +import org.apache.commons.compress.archivers.ArchiveException; import org.apache.commons.compress.utils.ArchiveUtils; import org.apache.commons.io.IOUtils; import org.junit.jupiter.api.Test; @@ -65,14 +66,14 @@ private void checkLongNameEntry(final String archive) throws Exception { void testCantReadAfterClose() throws Exception { try (ArArchiveInputStream archive = ArArchiveInputStream.builder().setURI(getURI("bla.ar")).get()) { archive.close(); - assertThrows(IllegalStateException.class, () -> archive.read()); + assertThrows(ArchiveException.class, () -> archive.read()); } } @Test void testCantReadWithoutOpeningAnEntry() throws Exception { try (ArArchiveInputStream archive = ArArchiveInputStream.builder().setURI(getURI("bla.ar")).get()) { - assertThrows(IllegalStateException.class, () -> archive.read()); + assertThrows(ArchiveException.class, () -> archive.read()); } }
