You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2025/04/25 14:23:30 UTC

(commons-compress) branch master updated (0969a95a6 -> 52434dd1e)

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

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


    from 0969a95a6 Bump github/codeql-action from 3.28.15 to 3.28.16 (#667)
     new 6c4474f3f Throw a better exception in org.apache.commons.compress.archivers.sevenz.SevenZFile.readFilesInfo(ByteBuffer, Archive)
     new b505079ad Add org.apache.commons.compress.compressors.CompressorException as the root for all custom exceptions ArchiveException and CompressorException
     new 9592c977a DumpArchiveException now extends ArchiveException instead of IOException (ArchiveException extends IOException)
     new ad42f9b1c Javadoc
     new ff86a0948 MemoryLimitException now extends CompressException instead of IOException (CompressException extends IOException)
     new c1b765ab8 PasswordRequiredException now extends CompressException instead of IOException (CompressException extends IOException)
     new dae91be83 Pack200Exception now extends CompressException instead of IOException (CompressException extends IOException)
     new 354788aaf ArArchiveInputStream.getBSDLongName(String) now throws its EOFException with a message
     new 4f6b08190 Don't use deprecated API
     new 52434dd1e Inline single use local variable

The 10 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/changes/changes.xml                            | 10 +++
 .../apache/commons/compress/CompressException.java | 95 ++++++++++++++++++++++
 .../commons/compress/MemoryLimitException.java     |  4 +-
 .../compress/PasswordRequiredException.java        |  4 +-
 .../compress/archivers/ArchiveException.java       | 54 +++++++++++-
 .../compress/archivers/ArchiveStreamFactory.java   |  6 +-
 .../archivers/ar/ArArchiveInputStream.java         |  2 +-
 .../archivers/arj/ArjArchiveInputStream.java       |  4 +-
 .../archivers/dump/DumpArchiveException.java       |  4 +-
 .../archivers/dump/DumpArchiveInputStream.java     |  4 +-
 .../compress/archivers/sevenz/SevenZFile.java      |  7 +-
 .../compress/compressors/CompressorException.java  |  4 +-
 .../compress/harmony/pack200/Pack200Exception.java |  4 +-
 .../utils/FixedLengthBlockOutputStream.java        |  3 +-
 14 files changed, 177 insertions(+), 28 deletions(-)
 create mode 100644 src/main/java/org/apache/commons/compress/CompressException.java


(commons-compress) 09/10: Don't use deprecated API

Posted by gg...@apache.org.
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 4f6b08190d28b35a7f0de5c3c559a08488f43c17
Author: Gary D. Gregory <ga...@gmail.com>
AuthorDate: Fri Apr 25 09:27:18 2025 -0400

    Don't use deprecated API
    
    Normalize exception variable name
---
 .../org/apache/commons/compress/archivers/ArchiveStreamFactory.java | 6 +++---
 .../commons/compress/archivers/arj/ArjArchiveInputStream.java       | 4 ++--
 .../commons/compress/archivers/dump/DumpArchiveInputStream.java     | 4 ++--
 3 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/src/main/java/org/apache/commons/compress/archivers/ArchiveStreamFactory.java b/src/main/java/org/apache/commons/compress/archivers/ArchiveStreamFactory.java
index c16f7cc3a..42dc976d0 100644
--- a/src/main/java/org/apache/commons/compress/archivers/ArchiveStreamFactory.java
+++ b/src/main/java/org/apache/commons/compress/archivers/ArchiveStreamFactory.java
@@ -224,7 +224,7 @@ public static String detect(final InputStream in) throws ArchiveException {
             signatureLength = IOUtils.readFully(in, signature);
             in.reset();
         } catch (final IOException e) {
-            throw new ArchiveException("Failure reading signature.", e);
+            throw new ArchiveException("Failure reading signature.", (Throwable) e);
         }
 
         // For now JAR files are detected as ZIP files.
@@ -255,7 +255,7 @@ public static String detect(final InputStream in) throws ArchiveException {
             signatureLength = IOUtils.readFully(in, dumpsig);
             in.reset();
         } catch (final IOException e) {
-            throw new ArchiveException("IOException while reading dump signature", e);
+            throw new ArchiveException("IOException while reading dump signature", (Throwable) e);
         }
         if (DumpArchiveInputStream.matches(dumpsig, signatureLength)) {
             return DUMP;
@@ -268,7 +268,7 @@ public static String detect(final InputStream in) throws ArchiveException {
             signatureLength = IOUtils.readFully(in, tarHeader);
             in.reset();
         } catch (final IOException e) {
-            throw new ArchiveException("IOException while reading tar signature", e);
+            throw new ArchiveException("IOException while reading tar signature", (Throwable) e);
         }
         if (TarArchiveInputStream.matches(tarHeader, signatureLength)) {
             return TAR;
diff --git a/src/main/java/org/apache/commons/compress/archivers/arj/ArjArchiveInputStream.java b/src/main/java/org/apache/commons/compress/archivers/arj/ArjArchiveInputStream.java
index aab56e76d..02c4f226b 100644
--- a/src/main/java/org/apache/commons/compress/archivers/arj/ArjArchiveInputStream.java
+++ b/src/main/java/org/apache/commons/compress/archivers/arj/ArjArchiveInputStream.java
@@ -94,8 +94,8 @@ public ArjArchiveInputStream(final InputStream inputStream, final String charset
             if ((mainHeader.arjFlags & MainHeader.Flags.VOLUME) != 0) {
                 throw new ArchiveException("Multi-volume ARJ files are unsupported");
             }
-        } catch (final IOException ioException) {
-            throw new ArchiveException(ioException.getMessage(), ioException);
+        } catch (final IOException e) {
+            throw new ArchiveException(e.getMessage(), (Throwable) e);
         }
     }
 
diff --git a/src/main/java/org/apache/commons/compress/archivers/dump/DumpArchiveInputStream.java b/src/main/java/org/apache/commons/compress/archivers/dump/DumpArchiveInputStream.java
index 8f118b8d9..232fce28b 100644
--- a/src/main/java/org/apache/commons/compress/archivers/dump/DumpArchiveInputStream.java
+++ b/src/main/java/org/apache/commons/compress/archivers/dump/DumpArchiveInputStream.java
@@ -148,8 +148,8 @@ public DumpArchiveInputStream(final InputStream is, final String encoding) throw
             // skip past CLRI and BITS segments since we don't handle them yet.
             readCLRI();
             readBITS();
-        } catch (final IOException ex) {
-            throw new ArchiveException(ex.getMessage(), ex);
+        } catch (final IOException e) {
+            throw new ArchiveException(e.getMessage(), (Throwable) e);
         }
 
         // put in a dummy record for the root node.


(commons-compress) 04/10: Javadoc

Posted by gg...@apache.org.
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 ad42f9b1c074f6d12bfc59339423eee488d42833
Author: Gary D. Gregory <ga...@gmail.com>
AuthorDate: Fri Apr 25 09:06:00 2025 -0400

    Javadoc
---
 src/main/java/org/apache/commons/compress/CompressException.java | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/main/java/org/apache/commons/compress/CompressException.java b/src/main/java/org/apache/commons/compress/CompressException.java
index 2ae933edb..46d1db19c 100644
--- a/src/main/java/org/apache/commons/compress/CompressException.java
+++ b/src/main/java/org/apache/commons/compress/CompressException.java
@@ -25,7 +25,7 @@
 import org.apache.commons.lang3.function.Suppliers;
 
 /**
- * Signals that an Compress exception of some sort has occurred.
+ * Signals that a Pack200 Compress exception of some sort has occurred.
  *
  * @since 1.28.0
  */


(commons-compress) 06/10: PasswordRequiredException now extends CompressException instead of IOException (CompressException extends IOException)

Posted by gg...@apache.org.
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 c1b765ab8a175e1e70869c17cf374a4946fa48b3
Author: Gary D. Gregory <ga...@gmail.com>
AuthorDate: Fri Apr 25 09:09:55 2025 -0400

    PasswordRequiredException now extends CompressException instead of
    IOException (CompressException extends IOException)
---
 src/changes/changes.xml                                               | 1 +
 .../java/org/apache/commons/compress/PasswordRequiredException.java   | 4 +---
 2 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index ddab3b63c..99d96299a 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -91,6 +91,7 @@ The <action> type attribute can be add,update,fix,remove.
       <action type="fix" dev="ggregory" due-to="Zaki, Gary Gregory">Throw a better exception in org.apache.commons.compress.archivers.sevenz.SevenZFile.readFilesInfo(ByteBuffer, Archive).</action>
       <action type="fix" dev="ggregory" due-to="Gary Gregory">MemoryLimitException now extends CompressException instead of IOException (CompressException extends IOException).</action>
       <action type="fix" dev="ggregory" due-to="Gary Gregory">DumpArchiveException now extends ArchiveException instead of IOException (ArchiveException extends CompressException).</action>
+      <action type="fix" dev="ggregory" due-to="Gary Gregory">PasswordRequiredException now extends CompressException instead of IOException (CompressException extends IOException).</action>
       <!-- ADD -->
       <action type="add" dev="ggregory" due-to="Gary Gregory">Add GzipParameters.getModificationInstant().</action>
       <action type="add" dev="ggregory" due-to="Gary Gregory">Add GzipParameters.setModificationInstant(Instant).</action>
diff --git a/src/main/java/org/apache/commons/compress/PasswordRequiredException.java b/src/main/java/org/apache/commons/compress/PasswordRequiredException.java
index f4affa9d8..0187b1b7d 100644
--- a/src/main/java/org/apache/commons/compress/PasswordRequiredException.java
+++ b/src/main/java/org/apache/commons/compress/PasswordRequiredException.java
@@ -18,14 +18,12 @@
  */
 package org.apache.commons.compress;
 
-import java.io.IOException;
-
 /**
  * Exception thrown when trying to read an encrypted entry or file without configuring a password.
  *
  * @since 1.10
  */
-public class PasswordRequiredException extends IOException {
+public class PasswordRequiredException extends CompressException {
 
     private static final long serialVersionUID = 1391070005491684483L;
 


(commons-compress) 10/10: Inline single use local variable

Posted by gg...@apache.org.
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 52434dd1eca0ca965a14637351157c23ac2fa972
Author: Gary D. Gregory <ga...@gmail.com>
AuthorDate: Fri Apr 25 09:59:18 2025 -0400

    Inline single use local variable
---
 .../apache/commons/compress/utils/FixedLengthBlockOutputStream.java    | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/src/main/java/org/apache/commons/compress/utils/FixedLengthBlockOutputStream.java b/src/main/java/org/apache/commons/compress/utils/FixedLengthBlockOutputStream.java
index ad5ce23c9..1e2589061 100644
--- a/src/main/java/org/apache/commons/compress/utils/FixedLengthBlockOutputStream.java
+++ b/src/main/java/org/apache/commons/compress/utils/FixedLengthBlockOutputStream.java
@@ -262,8 +262,7 @@ private void writeBlock() throws IOException {
         final int i = out.write(buffer);
         final boolean hasRemaining = buffer.hasRemaining();
         if (i != blockSize || hasRemaining) {
-            final String msg = String.format("Failed to write %,d bytes atomically. Only wrote  %,d", blockSize, i);
-            throw new IOException(msg);
+            throw new IOException(String.format("Failed to write %,d bytes atomically. Only wrote  %,d", blockSize, i));
         }
         buffer.clear();
     }


(commons-compress) 02/10: Add org.apache.commons.compress.compressors.CompressorException as the root for all custom exceptions ArchiveException and CompressorException

Posted by gg...@apache.org.
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 <ga...@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;


(commons-compress) 03/10: DumpArchiveException now extends ArchiveException instead of IOException (ArchiveException extends IOException)

Posted by gg...@apache.org.
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 9592c977a1981d8ce1c67ddb30adae05a6197988
Author: Gary D. Gregory <ga...@gmail.com>
AuthorDate: Fri Apr 25 09:04:18 2025 -0400

    DumpArchiveException now extends ArchiveException instead of IOException
    (ArchiveException extends IOException)
    
    - Add ArchiveException.ArchiveException(String, Throwable)
    - Add ArchiveException.ArchiveException(Throwable)
---
 src/changes/changes.xml                            |  3 ++
 .../apache/commons/compress/CompressException.java | 17 +++++++++++
 .../compress/archivers/ArchiveException.java       | 34 ++++++++++++++++++++++
 .../archivers/dump/DumpArchiveException.java       |  4 +--
 4 files changed, 56 insertions(+), 2 deletions(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 20bc9456f..f0e23bcfa 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -89,6 +89,7 @@ The <action> type attribute can be add,update,fix,remove.
       <action type="fix" dev="ggregory" due-to="Alexis Jehan, Gary Gregory">org.apache.commons.compress.harmony.unpack200.Archive.unpack() should not log to system out (the console).</action>
       <action type="fix" dev="Sebb" due-to="aSemy">[site] Fix minor zip docs type: remove extraneous 'a' #665.</action>
       <action type="fix" dev="ggregory" due-to="Zaki, Gary Gregory">Throw a better exception in org.apache.commons.compress.archivers.sevenz.SevenZFile.readFilesInfo(ByteBuffer, Archive).</action>
+      <action type="fix" dev="ggregory" due-to="Gary Gregory">DumpArchiveException now extends ArchiveException instead of IOException (ArchiveException extends IOException).</action>
       <!-- ADD -->
       <action type="add" dev="ggregory" due-to="Gary Gregory">Add GzipParameters.getModificationInstant().</action>
       <action type="add" dev="ggregory" due-to="Gary Gregory">Add GzipParameters.setModificationInstant(Instant).</action>
@@ -120,6 +121,8 @@ 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.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>
+      <action type="add" dev="ggregory" due-to="Gary Gregory">Add ArchiveException.ArchiveException(String, Throwable).</action>
+      <action type="add" dev="ggregory" due-to="Gary Gregory">Add ArchiveException.ArchiveException(Throwable).</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/CompressException.java b/src/main/java/org/apache/commons/compress/CompressException.java
index b2821c91d..2ae933edb 100644
--- a/src/main/java/org/apache/commons/compress/CompressException.java
+++ b/src/main/java/org/apache/commons/compress/CompressException.java
@@ -56,6 +56,13 @@ protected static <T, E extends Throwable> T requireNonNull(final Class<? super E
         return obj;
     }
 
+    /**
+     * Constructs an {@code CompressException} with {@code null} as its error detail message.
+     */
+    public CompressException() {
+        // empty
+    }
+
     /**
      * Constructs a new exception with the specified detail message. The cause is not initialized.
      *
@@ -75,4 +82,14 @@ public CompressException(final String message) {
     public CompressException(final String message, final Throwable cause) {
         super(message, cause);
     }
+
+    /**
+     * Constructs a {@code CompressException} with the specified cause and a detail message.
+     *
+     * @param cause The cause (which is saved for later retrieval by the {@link #getCause()} method). (A null value is permitted, and indicates that the cause
+     *              is nonexistent or unknown.)
+     */
+    public CompressException(final Throwable cause) {
+        super(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 b04998ab1..3258aac82 100644
--- a/src/main/java/org/apache/commons/compress/archivers/ArchiveException.java
+++ b/src/main/java/org/apache/commons/compress/archivers/ArchiveException.java
@@ -44,6 +44,15 @@ public static <T> T requireNonNull(final T obj, final Supplier<String> messageSu
         return CompressException.requireNonNull(ArchiveException.class, obj, messageSupplier);
     }
 
+    /**
+     * Constructs an {@code ArchiveException} with {@code null} as its error detail message.
+     *
+     * @since 1.28.0
+     */
+    public ArchiveException() {
+        // empty
+    }
+
     /**
      * Constructs a new exception with the specified detail message. The cause is not initialized.
      *
@@ -59,8 +68,33 @@ public ArchiveException(final String message) {
      * @param message The message (which is saved for later retrieval by the {@link #getMessage()} method).
      * @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.
+     * @deprecated Use {@link #ArchiveException(String, Throwable)}.
      */
+    @Deprecated
     public ArchiveException(final String message, final Exception cause) {
         super(message, cause);
     }
+
+    /**
+     * Constructs a new exception with the specified detail message and cause.
+     *
+     * @param message The message (which is saved for later retrieval by the {@link #getMessage()} method).
+     * @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.
+     * @since 1.28.0
+     */
+    public ArchiveException(final String message, final Throwable cause) {
+        super(message, cause);
+    }
+
+    /**
+     * Constructs a {@code ArchiveException} with the specified cause and a detail message.
+     *
+     * @param cause The cause (which is saved for later retrieval by the {@link #getCause()} method). (A null value is permitted, and indicates that the cause
+     *              is nonexistent or unknown.)
+     * @since 1.28.0
+     */
+    public ArchiveException(final Throwable cause) {
+        super(cause);
+    }
 }
diff --git a/src/main/java/org/apache/commons/compress/archivers/dump/DumpArchiveException.java b/src/main/java/org/apache/commons/compress/archivers/dump/DumpArchiveException.java
index a908be7d8..cdac1941b 100644
--- a/src/main/java/org/apache/commons/compress/archivers/dump/DumpArchiveException.java
+++ b/src/main/java/org/apache/commons/compress/archivers/dump/DumpArchiveException.java
@@ -19,12 +19,12 @@
 
 package org.apache.commons.compress.archivers.dump;
 
-import java.io.IOException;
+import org.apache.commons.compress.archivers.ArchiveException;
 
 /**
  * Signals that an dump archive exception of some sort has occurred.
  */
-public class DumpArchiveException extends IOException {
+public class DumpArchiveException extends ArchiveException {
 
     private static final long serialVersionUID = 1L;
 


(commons-compress) 07/10: Pack200Exception now extends CompressException instead of IOException (CompressException extends IOException)

Posted by gg...@apache.org.
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 dae91be8335789d5778ad944758b652e66d924de
Author: Gary D. Gregory <ga...@gmail.com>
AuthorDate: Fri Apr 25 09:11:22 2025 -0400

    Pack200Exception now extends CompressException instead of IOException
    (CompressException extends IOException)
---
 src/changes/changes.xml                                               | 1 +
 .../org/apache/commons/compress/harmony/pack200/Pack200Exception.java | 4 ++--
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 99d96299a..129c1662f 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -92,6 +92,7 @@ The <action> type attribute can be add,update,fix,remove.
       <action type="fix" dev="ggregory" due-to="Gary Gregory">MemoryLimitException now extends CompressException instead of IOException (CompressException extends IOException).</action>
       <action type="fix" dev="ggregory" due-to="Gary Gregory">DumpArchiveException now extends ArchiveException instead of IOException (ArchiveException extends CompressException).</action>
       <action type="fix" dev="ggregory" due-to="Gary Gregory">PasswordRequiredException now extends CompressException instead of IOException (CompressException extends IOException).</action>
+      <action type="fix" dev="ggregory" due-to="Gary Gregory">Pack200Exception now extends CompressException instead of IOException (CompressException extends IOException).</action>
       <!-- ADD -->
       <action type="add" dev="ggregory" due-to="Gary Gregory">Add GzipParameters.getModificationInstant().</action>
       <action type="add" dev="ggregory" due-to="Gary Gregory">Add GzipParameters.setModificationInstant(Instant).</action>
diff --git a/src/main/java/org/apache/commons/compress/harmony/pack200/Pack200Exception.java b/src/main/java/org/apache/commons/compress/harmony/pack200/Pack200Exception.java
index 6cef75df4..b27093a76 100644
--- a/src/main/java/org/apache/commons/compress/harmony/pack200/Pack200Exception.java
+++ b/src/main/java/org/apache/commons/compress/harmony/pack200/Pack200Exception.java
@@ -19,12 +19,12 @@
 
 package org.apache.commons.compress.harmony.pack200;
 
-import java.io.IOException;
+import org.apache.commons.compress.CompressException;
 
 /**
  * Signals a problem with a Pack200 coding or decoding issue.
  */
-public class Pack200Exception extends IOException {
+public class Pack200Exception extends CompressException {
 
     private static final long serialVersionUID = 5168177401552611803L;
 


(commons-compress) 01/10: Throw a better exception in org.apache.commons.compress.archivers.sevenz.SevenZFile.readFilesInfo(ByteBuffer, Archive)

Posted by gg...@apache.org.
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 6c4474f3f9c7418538ff3e1fdaa6ab90c96514b0
Author: Gary D. Gregory <ga...@gmail.com>
AuthorDate: Fri Apr 25 08:38:20 2025 -0400

    Throw a better exception in
    org.apache.commons.compress.archivers.sevenz.SevenZFile.readFilesInfo(ByteBuffer,
    Archive)
    
    - Add org.apache.commons.compress.archivers.ArchiveException.requireNonNull(T,
    Supplier<String>)
---
 src/changes/changes.xml                                |  2 ++
 .../commons/compress/archivers/ArchiveException.java   | 18 ++++++++++++++++++
 .../commons/compress/archivers/sevenz/SevenZFile.java  |  7 +++----
 3 files changed, 23 insertions(+), 4 deletions(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 884f61b45..85cde0d85 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -88,6 +88,7 @@ The <action> type attribute can be add,update,fix,remove.
       <action type="fix" dev="ggregory" due-to="Gary Gregory">Deprecate FileNameUtils#getExtension(Path).</action>
       <action type="fix" dev="ggregory" due-to="Alexis Jehan, Gary Gregory">org.apache.commons.compress.harmony.unpack200.Archive.unpack() should not log to system out (the console).</action>
       <action type="fix" dev="Sebb" due-to="aSemy">[site] Fix minor zip docs type: remove extraneous 'a' #665.</action>
+      <action type="fix" dev="ggregory" due-to="Zaki, Gary Gregory">Throw a better exception in org.apache.commons.compress.archivers.sevenz.SevenZFile.readFilesInfo(ByteBuffer, Archive).</action>
       <!-- ADD -->
       <action type="add" dev="ggregory" due-to="Gary Gregory">Add GzipParameters.getModificationInstant().</action>
       <action type="add" dev="ggregory" due-to="Gary Gregory">Add GzipParameters.setModificationInstant(Instant).</action>
@@ -117,6 +118,7 @@ The <action> type attribute can be add,update,fix,remove.
       <action type="add" dev="ggregory" due-to="Gary Gregory">Add org.apache.commons.compress.compressors.xz.XZCompressorOutputStream.builder/Builder().</action>
       <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>
       <!-- 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/archivers/ArchiveException.java
index ab14a5a10..29bb12214 100644
--- a/src/main/java/org/apache/commons/compress/archivers/ArchiveException.java
+++ b/src/main/java/org/apache/commons/compress/archivers/ArchiveException.java
@@ -19,6 +19,7 @@
 package org.apache.commons.compress.archivers;
 
 import java.io.IOException;
+import java.util.function.Supplier;
 
 /**
  * Signals that an Archive exception of some sort has occurred.
@@ -28,6 +29,23 @@ public class ArchiveException extends IOException {
     /** Serial. */
     private static final long serialVersionUID = 2772690708123267100L;
 
+    /**
+     * Checks that the specified object reference is not {@code null} and throws a customized {@link ArchiveException} if it is. *
+     *
+     * @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
+     */
+    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;
+    }
+
     /**
      * Constructs a new exception with the specified detail message. The cause is not initialized.
      *
diff --git a/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZFile.java b/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZFile.java
index 73402796f..0534f1554 100644
--- a/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZFile.java
+++ b/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZFile.java
@@ -50,6 +50,7 @@
 import java.util.zip.CheckedInputStream;
 
 import org.apache.commons.compress.MemoryLimitException;
+import org.apache.commons.compress.archivers.ArchiveException;
 import org.apache.commons.compress.utils.ByteUtils;
 import org.apache.commons.compress.utils.IOUtils;
 import org.apache.commons.compress.utils.InputStreamStatistics;
@@ -1290,11 +1291,11 @@ private void readFilesInfo(final ByteBuffer header, final Archive archive) throw
                 break;
             }
             case NID.kEmptyFile: {
-                isEmptyFile = readBits(header, isEmptyStream.cardinality());
+                isEmptyFile = readBits(header, ArchiveException.requireNonNull(isEmptyStream, () -> "isEmptyStream for " + archive).cardinality());
                 break;
             }
             case NID.kAnti: {
-                isAnti = readBits(header, isEmptyStream.cardinality());
+                isAnti = readBits(header, ArchiveException.requireNonNull(isEmptyStream, () -> "isEmptyStream for " + archive).cardinality());
                 break;
             }
             case NID.kName: {
@@ -1372,11 +1373,9 @@ private void readFilesInfo(final ByteBuffer header, final Archive archive) throw
             case NID.kDummy: {
                 // 7z 9.20 asserts the content is all zeros and ignores the property
                 // Compress up to 1.8.1 would throw an exception, now we ignore it (see COMPRESS-287
-
                 skipBytesFully(header, size);
                 break;
             }
-
             default: {
                 // Compress up to 1.8.1 would throw an exception, now we ignore it (see COMPRESS-287
                 skipBytesFully(header, size);


(commons-compress) 08/10: ArArchiveInputStream.getBSDLongName(String) now throws its EOFException with a message

Posted by gg...@apache.org.
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 354788aaff3196906f9c530596072c145c0c6156
Author: Gary D. Gregory <ga...@gmail.com>
AuthorDate: Fri Apr 25 09:14:17 2025 -0400

    ArArchiveInputStream.getBSDLongName(String) now throws its EOFException
    with a message
---
 src/changes/changes.xml                                                 | 1 +
 .../org/apache/commons/compress/archivers/ar/ArArchiveInputStream.java  | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 129c1662f..88792e07c 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -93,6 +93,7 @@ The <action> type attribute can be add,update,fix,remove.
       <action type="fix" dev="ggregory" due-to="Gary Gregory">DumpArchiveException now extends ArchiveException instead of IOException (ArchiveException extends CompressException).</action>
       <action type="fix" dev="ggregory" due-to="Gary Gregory">PasswordRequiredException now extends CompressException instead of IOException (CompressException extends IOException).</action>
       <action type="fix" dev="ggregory" due-to="Gary Gregory">Pack200Exception now extends CompressException instead of IOException (CompressException extends IOException).</action>
+      <action type="fix" dev="ggregory" due-to="Gary Gregory">ArArchiveInputStream.getBSDLongName(String) now throws its EOFException with a message.</action>
       <!-- ADD -->
       <action type="add" dev="ggregory" due-to="Gary Gregory">Add GzipParameters.getModificationInstant().</action>
       <action type="add" dev="ggregory" due-to="Gary Gregory">Add GzipParameters.setModificationInstant(Instant).</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 02bd2a795..3b2264415 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
@@ -205,7 +205,7 @@ private String getBSDLongName(final String bsdLongName) throws IOException {
         final int read = name.length;
         trackReadBytes(read);
         if (read != nameLen) {
-            throw new EOFException();
+            throw new EOFException(bsdLongName);
         }
         return ArchiveUtils.toAsciiString(name);
     }


(commons-compress) 05/10: MemoryLimitException now extends CompressException instead of IOException (CompressException extends IOException)

Posted by gg...@apache.org.
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 ff86a094800c7488254833e1cd15bb84c9dadf7c
Author: Gary D. Gregory <ga...@gmail.com>
AuthorDate: Fri Apr 25 09:08:22 2025 -0400

    MemoryLimitException now extends CompressException instead of
    IOException (CompressException extends IOException)
---
 src/changes/changes.xml                                             | 3 ++-
 src/main/java/org/apache/commons/compress/MemoryLimitException.java | 4 +---
 2 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index f0e23bcfa..ddab3b63c 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -89,7 +89,8 @@ The <action> type attribute can be add,update,fix,remove.
       <action type="fix" dev="ggregory" due-to="Alexis Jehan, Gary Gregory">org.apache.commons.compress.harmony.unpack200.Archive.unpack() should not log to system out (the console).</action>
       <action type="fix" dev="Sebb" due-to="aSemy">[site] Fix minor zip docs type: remove extraneous 'a' #665.</action>
       <action type="fix" dev="ggregory" due-to="Zaki, Gary Gregory">Throw a better exception in org.apache.commons.compress.archivers.sevenz.SevenZFile.readFilesInfo(ByteBuffer, Archive).</action>
-      <action type="fix" dev="ggregory" due-to="Gary Gregory">DumpArchiveException now extends ArchiveException instead of IOException (ArchiveException extends IOException).</action>
+      <action type="fix" dev="ggregory" due-to="Gary Gregory">MemoryLimitException now extends CompressException instead of IOException (CompressException extends IOException).</action>
+      <action type="fix" dev="ggregory" due-to="Gary Gregory">DumpArchiveException now extends ArchiveException instead of IOException (ArchiveException extends CompressException).</action>
       <!-- ADD -->
       <action type="add" dev="ggregory" due-to="Gary Gregory">Add GzipParameters.getModificationInstant().</action>
       <action type="add" dev="ggregory" due-to="Gary Gregory">Add GzipParameters.setModificationInstant(Instant).</action>
diff --git a/src/main/java/org/apache/commons/compress/MemoryLimitException.java b/src/main/java/org/apache/commons/compress/MemoryLimitException.java
index 6527876f1..d779b3b5d 100644
--- a/src/main/java/org/apache/commons/compress/MemoryLimitException.java
+++ b/src/main/java/org/apache/commons/compress/MemoryLimitException.java
@@ -18,15 +18,13 @@
  */
 package org.apache.commons.compress;
 
-import java.io.IOException;
-
 /**
  * If a stream checks for estimated memory allocation, and the estimate goes above the memory limit, this is thrown. This can also be thrown if a stream tries
  * to allocate a byte array that is larger than the allowable limit.
  *
  * @since 1.14
  */
-public class MemoryLimitException extends IOException {
+public class MemoryLimitException extends CompressException {
 
     private static final long serialVersionUID = 1L;