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 2026/08/10 22:11:13 UTC

(commons-compress) 07/10: CpioArchiveInputStream now throws ArchiveException instead of IllegalArgumentException.

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 9038888a2d2d29e476ad52b8138bb9e36ea08522
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Mon Aug 10 18:03:47 2026 -0400

    CpioArchiveInputStream now throws ArchiveException instead of
    IllegalArgumentException.
---
 src/changes/changes.xml                                    |  1 +
 .../compress/archivers/cpio/CpioArchiveInputStream.java    | 14 ++++++--------
 2 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index cccdaf14e..207d0be51 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -133,6 +133,7 @@ The <action> type attribute can be add,update,fix,remove.
       <action type="fix" issue="COMPRESS-718" dev="ggregory" due-to="Anay Wadhera, Gary Gregory">CpioArchiveEntry does not allow files over 4GB in OLD_ASCII format.</action>
       <action type="fix" dev="ggregory" due-to="Christopher Linke, Gary Gregory">Throw ArchiveException instead of EOFException when CPIO name size less than or equal to 0 #771.</action>
       <action type="fix" dev="ggregory" due-to="Gary Gregory">CpioArchiveEntry now throws ArchiveException instead of IllegalArgumentException.</action>
+      <action type="fix" dev="ggregory" due-to="Gary Gregory">CpioArchiveInputStream now throws ArchiveException instead of IllegalArgumentException.</action>
       <!-- FIX gzip -->
       <action type="fix" dev="ggregory" due-to="Gary Gregory">GzipParameters.setOperatingSystem(int) now throws CompressorException on illegal input.</action>
       <action type="fix" issue="COMPRESS-705" dev="ggregory" due-to="Mario Fredenhagen, Gary Gregory">GZip IOException: Extra subfield length exceeds remaining bytes in extra field; use new option GzipCompressorInputStream.Builder.setIgnoreExtraField(boolean).</action>
diff --git a/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveInputStream.java b/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveInputStream.java
index 26da0d860..ff35629af 100644
--- a/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveInputStream.java
+++ b/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveInputStream.java
@@ -186,7 +186,7 @@ public static boolean matches(final byte[] signature, final int length) {
     private CpioArchiveInputStream(final Builder builder) throws IOException {
         super(builder);
         if (builder.blockSize <= 0) {
-            throw new IllegalArgumentException("blockSize must be bigger than 0");
+            throw new ArchiveException("blockSize must be bigger than 0");
         }
         this.blockSize = builder.blockSize;
         this.zipEncoding = ZipEncodingHelper.getZipEncoding(builder.getCharset());
@@ -227,7 +227,7 @@ public CpioArchiveInputStream(final InputStream in, final int blockSize) throws
      *
      * @param in        The cpio stream.
      * @param blockSize The block size of the archive.
-     * @param encoding  The encoding of file names to expect - use null for the platform's default.
+     * @param encoding  The encoding of file names to expect, use null for the platform's default.
      * @throws IllegalArgumentException if {@code blockSize} is not bigger than 0.
      * @throws IOException if an I/O error has occurred.
      * @since 1.6
@@ -244,7 +244,7 @@ public CpioArchiveInputStream(final InputStream in, final int blockSize, final S
      * <p>Since 1.29.0: throws {@link IOException}.</p>
      *
      * @param in       The cpio stream.
-     * @param encoding The encoding of file names to expect - use null for the platform's default.
+     * @param encoding The encoding of file names to expect, use null for the platform's default.
      * @throws IOException if an I/O error has occurred.
      * @since 1.6
      * @deprecated Since 1.29.0, use {@link #builder()}.
@@ -542,14 +542,12 @@ private int skip(final int length) throws IOException {
      *
      * @param n The number of bytes to skip.
      * @return The actual number of bytes skipped.
-     * @throws IOException              if an I/O error has occurred.
-     * @throws IllegalArgumentException if n &lt; 0.
+     * @throws IOException      Thrown if an I/O error has occurred.
+     * @throws ArchiveException Thrown if n &lt; 0.
      */
     @Override
     public long skip(final long n) throws IOException {
-        if (n < 0) {
-            throw new IllegalArgumentException("Negative skip length");
-        }
+        ArchiveException.requireNonNegative(n, "Negative skip length");
         checkOpen();
         final int max = (int) Math.min(n, Integer.MAX_VALUE);
         int total = 0;