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 3598ef85247ea9382bd82100ac062d10955cbbd8
Author: Gary Gregory <[email protected]>
AuthorDate: Tue Aug 11 09:52:58 2026 -0400

    [LZ4] BlockLZ4CompressorOutputStream now throws ArchiveException instead
    of IllegalArgumetException/IllegalStateException.
    
    - [GZip] GzipCompressorInputStream now throws ArchiveException instead
    of IllegalArgumetException/IllegalStateException.
    - [Zip] UnshrinkingInputStreamnow now throws ArchiveException instead of
    IllegalArgumetException/IllegalStateException.
    - [Zip] UnshrinkingInputStreamnow now throws CompressorException instead
    of IllegalArgumetException/IllegalStateException.
---
 src/changes/changes.xml                                | 15 ++++++++++-----
 .../compress/archivers/zip/UnshrinkingInputStream.java |  4 +++-
 .../compressors/gzip/GzipCompressorInputStream.java    |  2 +-
 .../lz4/BlockLZ4CompressorOutputStream.java            | 10 +++++-----
 .../compress/compressors/lzw/LZWInputStream.java       | 18 +++++++++---------
 .../compressors/z/ZCompressorInputStreamTest.java      |  3 ++-
 6 files changed, 30 insertions(+), 22 deletions(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 56615cfb3..2850534aa 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -94,6 +94,7 @@ The <action> type attribute can be add,update,fix,remove.
       <action type="fix" dev="pkarwasz" due-to="Zach Warneke, Gary 
Gregory">[Zip] Fix NullPointerException when reading XZ entries in 
ZipArchiveInputStream (#774).</action>
       <action type="fix" dev="pkarwasz" due-to="KALI 834X, Gary Gregory">[Zip] 
Fix Zip rcount field width in x0015 and x0016 certificate id extra fields 
(#787).</action>
       <action type="fix" dev="ggregory" due-to="KALI 834X, Gary Gregory">[Zip] 
Reject negative ZIP64 offsets in positionAtCentralDirectory64 (#794).</action>
+      <action type="fix" dev="ggregory" due-to="Gary Gregory">[Zip] 
UnshrinkingInputStreamnow now throws CompressorException instead of 
IllegalArgumetException/IllegalStateException.</action>
       <!-- FIX TAR -->
       <action type="fix" dev="pkarwasz" due-to="Tyler Nighswander, Piotr P. 
Karwasz, Gary Gregory">>[TAR] Uniform handling of special tar records in 
TarFile and TarArchiveInputStream.</action>
       <action type="fix" dev="ggregory" due-to="Gary Gregory, Stanislav 
Fort">[TAR] TarArchiveOutputStream now throws a ArchiveException instead of an 
OutOfMemoryError.</action>
@@ -149,14 +150,18 @@ The <action> type attribute can be add,update,fix,remove.
       <action type="fix" dev="ggregory" due-to="Stanislav Fort, Gary 
Gregory">[Snappy] Fix for when a valid raw Snappy stream with uncompressed size 
> 2 GiB used to decompress and then fail at physical EOF with a “Premature end 
of stream” exception instead of completing cleanly.</action>
       <!-- FIX deflate64 -->
       <action type="fix" dev="ggregory" due-to="KALI 834X, Gary 
Gregory">[Deflate64] Reject invalid literal/length and distance codes in 
Deflate64 decoder (#785).</action>
-      <action type="fix" dev="ggregory" due-to="Gary Gregory">[Deflate64] 
Deflate64CompressorInputStream now throws ArchiveException instead of 
IllegalArgumetException/IllegalStateException.</action>
-      <action type="fix" dev="ggregory" due-to="Gary Gregory">[Deflate64] 
Deflate64Decoder now throws ArchiveException instead of 
IllegalArgumetException/IllegalStateException.</action>
+      <action type="fix" dev="ggregory" due-to="Gary Gregory">[Deflate64] 
Deflate64CompressorInputStream now throws CompressorException instead of 
IllegalArgumetException/IllegalStateException.</action>
+      <action type="fix" dev="ggregory" due-to="Gary Gregory">[Deflate64] 
Deflate64Decoder now throws CompressorException instead of 
IllegalArgumetException/IllegalStateException.</action>
       <!-- FIX lz77 -->
       <action type="fix" dev="ggregory" due-to="KALI 834X, Gary 
Gregory">[LZ77] Reject back-reference offset larger than the window in lz77 
decoder class AbstractLZ77CompressorInputStream (#797).</action>
-      <action type="fix" dev="ggregory" due-to="Gary Gregory">[LZ77] 
AbstractLZ77CompressorInputStream now throws ArchiveException instead of 
IllegalArgumetException/IllegalStateException.</action>
-      <action type="fix" dev="ggregory" due-to="Gary Gregory">[LZ77] 
LZ77Compressor.prefill(byte[]) now throws ArchiveException instead of 
IllegalArgumetException/IllegalStateException.</action>
+      <action type="fix" dev="ggregory" due-to="Gary Gregory">[LZ77] 
AbstractLZ77CompressorInputStream now throws CompressorException instead of 
IllegalArgumetException/IllegalStateException.</action>
+      <action type="fix" dev="ggregory" due-to="Gary Gregory">[LZ77] 
LZ77Compressor.prefill(byte[]) now throws CompressorException instead of 
IllegalArgumetException/IllegalStateException.</action>
       <!-- FIX lz4 -->
-      <action type="fix" dev="ggregory" due-to="Gary Gregory">[LZ4] 
BlockLZ4CompressorOutputStream.prefill(byte[], int, int) now throws 
ArchiveException instead of 
IllegalArgumetException/IllegalStateException.</action>
+      <action type="fix" dev="ggregory" due-to="Gary Gregory">[LZ4] 
BlockLZ4CompressorOutputStream now throws CompressorException instead of 
IllegalArgumetException/IllegalStateException.</action>
+      <!-- FIX gzip -->
+      <action type="fix" dev="ggregory" due-to="Gary Gregory">[GZip] 
GzipCompressorInputStream now throws CompressorException instead of 
IllegalArgumetException/IllegalStateException.</action>
+      <!-- FIX lzw -->
+      <action type="fix" dev="ggregory" due-to="Gary Gregory">[LZW] 
LZWInputStream now throws CompressorException instead of 
IllegalArgumetException/IllegalStateException.</action>
       <!-- FIX general -->      
       <action type="fix" dev="ggregory" due-to="Piotr P. Karwasz, Gary 
Gregory">Add missing Javadoc @since tag to 
org.apache.commons.compress.compressors.lz77support.LZ77Compressor.AbstractReference.</action>
       <action type="fix" dev="ggregory" due-to="Gary Gregory">Classes in 
org.apache.commons.compress.archivers now throw a subclass of IOException 
called ArchiveException instead of IOException when a formatting problem is 
found.</action>
diff --git 
a/src/main/java/org/apache/commons/compress/archivers/zip/UnshrinkingInputStream.java
 
b/src/main/java/org/apache/commons/compress/archivers/zip/UnshrinkingInputStream.java
index 45d9332dc..09b09efce 100644
--- 
a/src/main/java/org/apache/commons/compress/archivers/zip/UnshrinkingInputStream.java
+++ 
b/src/main/java/org/apache/commons/compress/archivers/zip/UnshrinkingInputStream.java
@@ -24,6 +24,7 @@
 import java.util.Arrays;
 
 import org.apache.commons.compress.archivers.ArchiveException;
+import org.apache.commons.compress.compressors.CompressorException;
 import org.apache.commons.compress.compressors.lzw.LZWInputStream;
 
 /**
@@ -41,8 +42,9 @@ final class UnshrinkingInputStream extends LZWInputStream {
      * Constructs a new instance.
      *
      * @param inputStream Input stream.
+     * @throws CompressorException Thrown if the input stream cannot 
configured.
      */
-    UnshrinkingInputStream(final InputStream inputStream) {
+    UnshrinkingInputStream(final InputStream inputStream) throws 
CompressorException {
         super(inputStream, ByteOrder.LITTLE_ENDIAN);
         setClearCode(DEFAULT_CODE_SIZE);
         initializeTables(MAX_CODE_SIZE);
diff --git 
a/src/main/java/org/apache/commons/compress/compressors/gzip/GzipCompressorInputStream.java
 
b/src/main/java/org/apache/commons/compress/compressors/gzip/GzipCompressorInputStream.java
index acdc9b3b3..318b86974 100644
--- 
a/src/main/java/org/apache/commons/compress/compressors/gzip/GzipCompressorInputStream.java
+++ 
b/src/main/java/org/apache/commons/compress/compressors/gzip/GzipCompressorInputStream.java
@@ -360,7 +360,7 @@ public GzipParameters getMetaData() {
 
     private boolean init(final boolean isFirstMember) throws IOException {
         if (!isFirstMember && !decompressConcatenated) { // at least one must 
be true
-            throw new IllegalStateException("Unexpected: isFirstMember and 
decompressConcatenated are both false.");
+            throw new CompressorException("Unexpected: isFirstMember and 
decompressConcatenated are both false.");
         }
         // Check the magic bytes without a possibility of EOFException.
         final int magic0 = in.read();
diff --git 
a/src/main/java/org/apache/commons/compress/compressors/lz4/BlockLZ4CompressorOutputStream.java
 
b/src/main/java/org/apache/commons/compress/compressors/lz4/BlockLZ4CompressorOutputStream.java
index 50ba00c5a..f0b6e2c71 100644
--- 
a/src/main/java/org/apache/commons/compress/compressors/lz4/BlockLZ4CompressorOutputStream.java
+++ 
b/src/main/java/org/apache/commons/compress/compressors/lz4/BlockLZ4CompressorOutputStream.java
@@ -292,7 +292,7 @@ public void close() throws IOException {
         }
     }
 
-    private byte[] expand(final int offset, final int length) {
+    private byte[] expand(final int offset, final int length) throws 
CompressorException {
         final byte[] expanded = new byte[length];
         if (offset == 1) { // surprisingly common special case
             final byte[] block = expandedBlocks.peekFirst();
@@ -306,7 +306,7 @@ private byte[] expand(final int offset, final int length) {
         return expanded;
     }
 
-    private void expandFromList(final byte[] expanded, final int offset, final 
int length) {
+    private void expandFromList(final byte[] expanded, final int offset, final 
int length) throws CompressorException {
         int offsetRemaining = offset;
         int lengthRemaining = length;
         int writeOffset = 0;
@@ -326,7 +326,7 @@ private void expandFromList(final byte[] expanded, final 
int offset, final int l
                 }
                 if (block == null) {
                     // should not be possible
-                    throw new IllegalStateException("Failed to find a block 
containing offset " + offset);
+                    throw new CompressorException("Failed to find a block 
containing offset " + offset);
                 }
                 copyOffset = blockOffset + block.length - offsetRemaining;
                 copyLen = Math.min(lengthRemaining, block.length - copyOffset);
@@ -373,7 +373,7 @@ public void prefill(final byte[] data, final int off, final 
int len) throws Comp
         }
     }
 
-    private void recordBackReference(final LZ77Compressor.BackReference block) 
{
+    private void recordBackReference(final LZ77Compressor.BackReference block) 
throws CompressorException {
         expandedBlocks.addFirst(expand(block.getOffset(), block.getLength()));
     }
 
@@ -381,7 +381,7 @@ private void recordLiteral(final byte[] b) {
         expandedBlocks.addFirst(b);
     }
 
-    private void rewriteLastPairs() {
+    private void rewriteLastPairs() throws CompressorException {
         final LinkedList<Pair> lastPairs = new LinkedList<>();
         final LinkedList<Integer> pairLength = new LinkedList<>();
         int offset = 0;
diff --git 
a/src/main/java/org/apache/commons/compress/compressors/lzw/LZWInputStream.java 
b/src/main/java/org/apache/commons/compress/compressors/lzw/LZWInputStream.java
index 87a464e6f..b2fc9e3ab 100644
--- 
a/src/main/java/org/apache/commons/compress/compressors/lzw/LZWInputStream.java
+++ 
b/src/main/java/org/apache/commons/compress/compressors/lzw/LZWInputStream.java
@@ -223,14 +223,14 @@ protected void incrementCodeSize() {
      * Initializes the arrays based on the maximum code size.
      *
      * @param maxCodeSize maximum code size.
-     * @throws IllegalArgumentException if {@code maxCodeSize} is out of 
bounds for {@code prefixes} and {@code characters}.
+     * @throws CompressorException if {@code maxCodeSize} is out of bounds for 
{@code prefixes} and {@code characters}.
      */
-    protected void initializeTables(final int maxCodeSize) {
+    protected void initializeTables(final int maxCodeSize) throws 
CompressorException {
         // maxCodeSize shifted cannot be less than 256, otherwise the loop in 
initializeTables() will throw an ArrayIndexOutOfBoundsException
         // maxCodeSize cannot be smaller than getCodeSize(), otherwise 
addEntry() will throw an ArrayIndexOutOfBoundsException
         if (1 << maxCodeSize < 256 || getCodeSize() > maxCodeSize) {
             // TODO test against prefixes.length and characters.length?
-            throw new IllegalArgumentException("maxCodeSize " + maxCodeSize + 
" is out of bounds.");
+            throw new CompressorException("maxCodeSize " + maxCodeSize + " is 
out of bounds.");
         }
         final int maxTableSize = 1 << maxCodeSize;
         prefixes = new int[maxTableSize];
@@ -247,14 +247,14 @@ protected void initializeTables(final int maxCodeSize) {
     /**
      * Initializes the arrays based on the maximum code size. First checks 
that the estimated memory usage is below memoryLimitInKb
      *
-     * @param maxCodeSize     maximum code size.
+     * @param maxCodeSize   maximum code size.
      * @param memoryLimiKiB maximum allowed estimated memory usage in 
kibibytes (KiB).
-     * @throws MemoryLimitException     if estimated memory usage is greater 
than memoryLimitKiB.
-     * @throws IllegalArgumentException if {@code maxCodeSize} is not bigger 
than 0.
+     * @throws MemoryLimitException Thrown if estimated memory usage is 
greater than memoryLimitKiB.
+     * @throws CompressorException  Thrown if {@code maxCodeSize} is not 
bigger than 0.
      */
-    protected void initializeTables(final int maxCodeSize, final int 
memoryLimiKiB) throws MemoryLimitException {
+    protected void initializeTables(final int maxCodeSize, final int 
memoryLimiKiB) throws MemoryLimitException, CompressorException {
         if (maxCodeSize <= 0) {
-            throw new IllegalArgumentException("maxCodeSize is " + maxCodeSize 
+ ", must be bigger than 0");
+            throw new CompressorException("maxCodeSize is " + maxCodeSize + ", 
must be bigger than 0");
         }
         if (memoryLimiKiB > -1) {
             final int maxTableSize = 1 << maxCodeSize;
@@ -316,7 +316,7 @@ private int readFromStack(final byte[] b, final int off, 
final int len) {
      */
     protected int readNextCode() throws IOException {
         if (codeSize > MAX_CODE_SIZE) {
-            throw new IllegalArgumentException("Code size must not be bigger 
than 31");
+            throw new CompressorException("Code size must not be bigger than 
31");
         }
         return (int) in.readBits(codeSize);
     }
diff --git 
a/src/test/java/org/apache/commons/compress/compressors/z/ZCompressorInputStreamTest.java
 
b/src/test/java/org/apache/commons/compress/compressors/z/ZCompressorInputStreamTest.java
index 95c4dd42e..55b6499f9 100644
--- 
a/src/test/java/org/apache/commons/compress/compressors/z/ZCompressorInputStreamTest.java
+++ 
b/src/test/java/org/apache/commons/compress/compressors/z/ZCompressorInputStreamTest.java
@@ -32,6 +32,7 @@
 import java.util.stream.Stream;
 
 import org.apache.commons.compress.AbstractTest;
+import org.apache.commons.compress.CompressException;
 import org.apache.commons.compress.compressors.CompressorException;
 import org.apache.commons.io.IOUtils;
 import org.junit.jupiter.api.Test;
@@ -70,7 +71,7 @@ void testInvalidMaxCodeSize() throws IOException {
 
         Stream.of(invalid).forEach(ints -> ints.forEach(i -> {
             bytes[2] = (byte) i;
-            assertThrows(IllegalArgumentException.class, () -> new 
ZCompressorInputStream(new ByteArrayInputStream(bytes), 1024 * 1024), () -> 
"value=" + i);
+            assertThrows(CompressException.class, () -> new 
ZCompressorInputStream(new ByteArrayInputStream(bytes), 1024 * 1024), () -> 
"value=" + i);
         }));
     }
 

Reply via email to