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

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

commit b505079ad9f2f0c8e8fdb84f69de3e17112ba07d
Author: Gary D. Gregory <garydgreg...@gmail.com>
AuthorDate: Fri Apr 25 08:54:04 2025 -0400

    Add org.apache.commons.compress.compressors.CompressorException as the
    root for all custom exceptions ArchiveException and CompressorException
---
 src/changes/changes.xml                            |  1 +
 ...rchiveException.java => CompressException.java} | 38 ++++++++++++++--------
 .../compress/archivers/ArchiveException.java       | 10 +++---
 .../compress/compressors/CompressorException.java  |  4 +--
 4 files changed, 31 insertions(+), 22 deletions(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 85cde0d85..20bc9456f 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -119,6 +119,7 @@ The <action> type attribute can be add,update,fix,remove.
       <action type="add" dev="ggregory" due-to="Gary Gregory, David Walluck, 
Piotr P. Karwasz">Add 
org.apache.commons.compress.compressors.xz.ZstdCompressorOutputStream.builder/Builder()
 #666.</action>
       <action type="add" dev="ggregory" due-to="Gary Gregory, David Walluck, 
Piotr P. Karwasz">Add org.apache.commons.compress.compressors.xz.ZstdConstants 
#666.</action>
       <action type="add" dev="ggregory" due-to="Gary Gregory, Zaki">Add 
org.apache.commons.compress.archivers.ArchiveException.requireNonNull(T, 
Supplier&lt;String&gt;).</action>
+      <action type="add" dev="ggregory" due-to="Gary Gregory">Add 
org.apache.commons.compress.compressors.CompressorException as the root for all 
custom exceptions ArchiveException and CompressorException.</action>
       <!-- UPDATE -->
       <action type="update" dev="sebb">Bump Commons Parent from 79 to 
81</action>
       <action type="update" dev="ggregory" due-to="Dependabot, Gary 
Gregory">Bump org.apache.commons:commons-parent from 72 to 79 #563, #567, #574, 
#582, #587, #595.</action>
diff --git 
a/src/main/java/org/apache/commons/compress/archivers/ArchiveException.java 
b/src/main/java/org/apache/commons/compress/CompressException.java
similarity index 60%
copy from 
src/main/java/org/apache/commons/compress/archivers/ArchiveException.java
copy to src/main/java/org/apache/commons/compress/CompressException.java
index 29bb12214..b2821c91d 100644
--- a/src/main/java/org/apache/commons/compress/archivers/ArchiveException.java
+++ b/src/main/java/org/apache/commons/compress/CompressException.java
@@ -16,32 +16,42 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.commons.compress.archivers;
+
+package org.apache.commons.compress;
 
 import java.io.IOException;
 import java.util.function.Supplier;
 
+import org.apache.commons.lang3.function.Suppliers;
+
 /**
- * Signals that an Archive exception of some sort has occurred.
+ * Signals that an Compress exception of some sort has occurred.
+ *
+ * @since 1.28.0
  */
-public class ArchiveException extends IOException {
+public class CompressException extends IOException {
 
     /** Serial. */
-    private static final long serialVersionUID = 2772690708123267100L;
+    private static final long serialVersionUID = 1;
 
     /**
-     * Checks that the specified object reference is not {@code null} and 
throws a customized {@link ArchiveException} if it is. *
+     * Checks that the specified object reference is not {@code null} and 
throws a customized {@link CompressException} if it is. *
      *
-     * @param obj             the object reference to check for nullity.
+     * @param <T>             The type of the reference.
+     * @param <E>             The type of the exception.
+     * @param cls             The exception class.
+     * @param obj             The object reference to check for nullity.
      * @param messageSupplier supplier of the detail message to be used in the 
event that a {@code ArchiveException} is thrown
-     * @param <T>             the type of the reference.
-     * @return {@code obj} if not {@code null}
-     * @throws ArchiveException if {@code obj} is {@code null}
-     * @since 1.28.0
+     * @return {@code obj} if not {@code null}.
+     * @throws E if {@code obj} is {@code null}.
      */
-    public static <T> T requireNonNull(final T obj, final Supplier<String> 
messageSupplier) throws ArchiveException {
+    protected static <T, E extends Throwable> T requireNonNull(final Class<? 
super E> cls, final T obj, final Supplier<String> messageSupplier) throws E {
         if (obj == null) {
-            throw new ArchiveException(messageSupplier == null ? null : 
messageSupplier.get());
+            try {
+                
cls.getConstructor(String.class).newInstance(Suppliers.get(messageSupplier));
+            } catch (ReflectiveOperationException | SecurityException e) {
+                new CompressException(Suppliers.get(messageSupplier), e);
+            }
         }
         return obj;
     }
@@ -51,7 +61,7 @@ public static <T> T requireNonNull(final T obj, final 
Supplier<String> messageSu
      *
      * @param message The message (which is saved for later retrieval by the 
{@link #getMessage()} method).
      */
-    public ArchiveException(final String message) {
+    public CompressException(final String message) {
         super(message);
     }
 
@@ -62,7 +72,7 @@ public ArchiveException(final String message) {
      * @param cause   The cause (which is saved for later retrieval by the 
{@link #getCause()} method). A null value indicates that the cause is 
nonexistent or
      *                unknown.
      */
-    public ArchiveException(final String message, final Exception cause) {
+    public CompressException(final String message, final Throwable cause) {
         super(message, cause);
     }
 }
diff --git 
a/src/main/java/org/apache/commons/compress/archivers/ArchiveException.java 
b/src/main/java/org/apache/commons/compress/archivers/ArchiveException.java
index 29bb12214..b04998ab1 100644
--- a/src/main/java/org/apache/commons/compress/archivers/ArchiveException.java
+++ b/src/main/java/org/apache/commons/compress/archivers/ArchiveException.java
@@ -18,13 +18,14 @@
  */
 package org.apache.commons.compress.archivers;
 
-import java.io.IOException;
 import java.util.function.Supplier;
 
+import org.apache.commons.compress.CompressException;
+
 /**
  * Signals that an Archive exception of some sort has occurred.
  */
-public class ArchiveException extends IOException {
+public class ArchiveException extends CompressException {
 
     /** Serial. */
     private static final long serialVersionUID = 2772690708123267100L;
@@ -40,10 +41,7 @@ public class ArchiveException extends IOException {
      * @since 1.28.0
      */
     public static <T> T requireNonNull(final T obj, final Supplier<String> 
messageSupplier) throws ArchiveException {
-        if (obj == null) {
-            throw new ArchiveException(messageSupplier == null ? null : 
messageSupplier.get());
-        }
-        return obj;
+        return CompressException.requireNonNull(ArchiveException.class, obj, 
messageSupplier);
     }
 
     /**
diff --git 
a/src/main/java/org/apache/commons/compress/compressors/CompressorException.java
 
b/src/main/java/org/apache/commons/compress/compressors/CompressorException.java
index 0220c8874..1192d5066 100644
--- 
a/src/main/java/org/apache/commons/compress/compressors/CompressorException.java
+++ 
b/src/main/java/org/apache/commons/compress/compressors/CompressorException.java
@@ -18,12 +18,12 @@
  */
 package org.apache.commons.compress.compressors;
 
-import java.io.IOException;
+import org.apache.commons.compress.CompressException;
 
 /**
  * Signals that an Compressor exception of some sort has occurred.
  */
-public class CompressorException extends IOException {
+public class CompressorException extends CompressException {
 
     /** Serial. */
     private static final long serialVersionUID = -2932901310255908814L;

Reply via email to