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 1c522228a7b7edd6824ec441a5e58bad9fcf52cc
Author: Gary Gregory <[email protected]>
AuthorDate: Tue Aug 11 14:22:06 2026 -0400

    ExactMath now throws ArchiveException instead of
    IllegalArgumetException/IllegalStateException.
---
 src/changes/changes.xml                                           | 1 +
 src/main/java/org/apache/commons/compress/utils/ExactMath.java    | 8 +++++---
 .../java/org/apache/commons/compress/utils/ExactMathTest.java     | 5 +++--
 3 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index e8788089f..95f2075c3 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -201,6 +201,7 @@ The <action> type attribute can be add,update,fix,remove.
       <action type="fix" dev="ggregory" due-to="Gary Gregory">Add and use 
ArchiveException.requireNonNegative(long, String)</action>
       <action type="fix" dev="ggregory" due-to="Gary Gregory">Add and use 
ArchiveException.requireNonNegative(long, Supplier&lt;String&gt;)</action>
       <action type="fix" dev="ggregory" due-to="Gary 
Gregory">ArchiveStreamFactory now throws ArchiveException instead of 
IllegalArgumetException/IllegalStateException.</action>
+      <action type="fix" dev="ggregory" due-to="Gary Gregory">ExactMath now 
throws ArchiveException instead of 
IllegalArgumetException/IllegalStateException.</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/utils/ExactMath.java 
b/src/main/java/org/apache/commons/compress/utils/ExactMath.java
index 7b5ca6641..e916789fb 100644
--- a/src/main/java/org/apache/commons/compress/utils/ExactMath.java
+++ b/src/main/java/org/apache/commons/compress/utils/ExactMath.java
@@ -19,6 +19,8 @@
 
 package org.apache.commons.compress.utils;
 
+import org.apache.commons.compress.CompressException;
+
 /**
  * PRIVATE.
  *
@@ -32,13 +34,13 @@ public class ExactMath {
      * @param x The first value, an int.
      * @param y The second value, a long,.
      * @return The addition of both values.
-     * @throws IllegalArgumentException when y or the result overflows an int.
+     * @throws CompressException when y or the result overflows an int.
      */
-    public static int add(final int x, final long y) {
+    public static int add(final int x, final long y) throws CompressException {
         try {
             return Math.addExact(x, Math.toIntExact(y));
         } catch (final ArithmeticException exp) {
-            throw new IllegalArgumentException("Argument too large or result 
overflows", exp);
+            throw new CompressException("Argument too large or result 
overflows", exp);
         }
     }
 
diff --git a/src/test/java/org/apache/commons/compress/utils/ExactMathTest.java 
b/src/test/java/org/apache/commons/compress/utils/ExactMathTest.java
index 270f08b3a..f6f991e47 100644
--- a/src/test/java/org/apache/commons/compress/utils/ExactMathTest.java
+++ b/src/test/java/org/apache/commons/compress/utils/ExactMathTest.java
@@ -20,14 +20,15 @@
 
 import static org.junit.jupiter.api.Assertions.assertThrows;
 
+import org.apache.commons.compress.CompressException;
 import org.junit.jupiter.api.Test;
 
 class ExactMathTest {
 
     @Test
     void testOverflow() {
-        assertThrows(IllegalArgumentException.class, () -> ExactMath.add(1, 
Long.MAX_VALUE / 1000));
-        assertThrows(IllegalArgumentException.class, () -> 
ExactMath.add(Integer.MAX_VALUE, Integer.MAX_VALUE));
+        assertThrows(CompressException.class, () -> ExactMath.add(1, 
Long.MAX_VALUE / 1000));
+        assertThrows(CompressException.class, () -> 
ExactMath.add(Integer.MAX_VALUE, Integer.MAX_VALUE));
     }
 
 }

Reply via email to