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 a0df6b63a36d1c0ea2550c85a34634a9d8715913
Author: Gary Gregory <[email protected]>
AuthorDate: Sun Aug 9 19:12:49 2026 -0400

    Most ArArchiveEntry constructors now throws the IOException subclass
    ArchiveException.
---
 src/changes/changes.xml                                  |  1 +
 .../commons/compress/archivers/ar/ArArchiveEntry.java    | 16 +++++++++-------
 .../compress/archivers/ar/ArArchiveInputStream.java      |  6 +++---
 3 files changed, 13 insertions(+), 10 deletions(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 848844988..d758fccc0 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -169,6 +169,7 @@ The <action> type attribute can be add,update,fix,remove.
       <action type="fix" dev="ggregory" due-to="Gary 
Gregory">TarArchiveEntry.setDevMinor(int) now throw ArchiveException instead of 
IllegalArgumentException.</action>
       <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">ParsingUtils now 
throws the IOException subclass CompressException.</action>
+      <action type="fix" dev="ggregory" due-to="Gary Gregory">Most 
ArArchiveEntry constructors now throws the IOException subclass 
ArchiveException.</action>
       <!-- ADD -->
       <action type="add" dev="ggregory" due-to="Gary Gregory">Add 
MemoryLimitException.MemoryLimitException(long, long).</action>
       <action type="add" dev="ggregory" due-to="Gary Gregory">Add 
CompressException.CompressException(String, Object...).</action>
diff --git 
a/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveEntry.java 
b/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveEntry.java
index efe49bb22..f05d0f963 100644
--- a/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveEntry.java
+++ b/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveEntry.java
@@ -29,6 +29,7 @@
 import java.util.concurrent.TimeUnit;
 
 import org.apache.commons.compress.archivers.ArchiveEntry;
+import org.apache.commons.compress.archivers.ArchiveException;
 
 /**
  * Represents an archive entry in the "ar" format.
@@ -86,8 +87,9 @@ public class ArArchiveEntry implements ArchiveEntry {
      *
      * @param inputFile The file to create an entry from.
      * @param entryName The name of the entry.
+     * @throws ArchiveException Thrown if the length is negative (this is an 
internal error).
      */
-    public ArArchiveEntry(final File inputFile, final String entryName) {
+    public ArArchiveEntry(final File inputFile, final String entryName) throws 
ArchiveException {
         // TODO sort out mode
         this(entryName, inputFile.isFile() ? inputFile.length() : 0, 0, 0, 
DEFAULT_MODE, TimeUnit.MILLISECONDS.toSeconds(inputFile.lastModified()));
     }
@@ -115,8 +117,9 @@ public ArArchiveEntry(final Path inputPath, final String 
entryName, final LinkOp
      *
      * @param name   name of the entry.
      * @param length length of the entry in bytes.
+     * @throws ArchiveException Thrown if the length is negative.
      */
-    public ArArchiveEntry(final String name, final long length) {
+    public ArArchiveEntry(final String name, final long length) throws 
ArchiveException {
         this(name, length, 0, 0, DEFAULT_MODE, 
TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis()));
     }
 
@@ -129,13 +132,12 @@ public ArArchiveEntry(final String name, final long 
length) {
      * @param groupId      numeric group id.
      * @param mode         file mode.
      * @param lastModified last modified time in seconds since the epoch.
+     * @throws ArchiveException Thrown if the length is negative.
      */
-    public ArArchiveEntry(final String name, final long length, final int 
userId, final int groupId, final int mode, final long lastModified) {
+    public ArArchiveEntry(final String name, final long length, final int 
userId, final int groupId, final int mode, final long lastModified)
+            throws ArchiveException {
         this.name = name;
-        if (length < 0) {
-            throw new IllegalArgumentException("Length must not be negative");
-        }
-        this.length = length;
+        this.length = ArchiveException.requireNonNegative(length, "Length must 
not be negative");
         this.userId = userId;
         this.groupId = groupId;
         this.mode = mode;
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 7014d6226..85a85e553 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
@@ -432,10 +432,10 @@ private ArArchiveEntry parseEntry(final byte[] headerBuf) 
throws ArchiveExceptio
             final int mode = asInt(metaData, FILE_MODE_OFFSET, FILE_MODE_LEN, 
8);
             final long lastModified = asLong(metaData, LAST_MODIFIED_OFFSET, 
LAST_MODIFIED_LEN);
             return new ArArchiveEntry(name, length, userId, groupId, mode, 
lastModified);
-        } catch (final IllegalArgumentException e) {
-            throw new ArchiveException("Broken archive, entry with negative 
size", (Throwable) e);
+        } catch (final ArchiveException e) {
+            throw e;
         } catch (final IOException e) {
-            throw new ArchiveException("Failed to parse ar entry.", 
(Throwable) e);
+            throw new ArchiveException("Failed to parse AR entry.", 
(Throwable) e);
         }
     }
 

Reply via email to