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 6214d160c7e0ace642484a0c8eaabc042dba3883 Author: Gary Gregory <[email protected]> AuthorDate: Tue Aug 11 07:23:56 2026 -0400 [LZ77] LZ77Compressor.prefill(byte[]) now throws ArchiveException instead of IllegalArgumentException. [LZ4] BlockLZ4CompressorOutputStream.prefill(byte[], int, int) now throws ArchiveException instead of IllegalArgumentException. --- src/changes/changes.xml | 3 +++ .../compress/compressors/lz4/BlockLZ4CompressorOutputStream.java | 5 +++-- .../commons/compress/compressors/lz77support/LZ77Compressor.java | 7 ++++--- .../compress/compressors/lz77support/LZ77CompressorTest.java | 7 ++++--- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 9206ad221..76fb4fb3c 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -148,6 +148,9 @@ The <action> type attribute can be add,update,fix,remove. <!-- 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 IllegalArgumentException.</action> + <action type="fix" dev="ggregory" due-to="Gary Gregory">[LZ77] LZ77Compressor.prefill(byte[]) now throws ArchiveException instead of IllegalArgumentException.</action> + <!-- FIX lz4 --> + <action type="fix" dev="ggregory" due-to="Gary Gregory">[LZ4] BlockLZ4CompressorOutputStream.prefill(byte[], int, int) now throws ArchiveException instead of IllegalArgumentException.</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/compressors/lz4/BlockLZ4CompressorOutputStream.java b/src/main/java/org/apache/commons/compress/compressors/lz4/BlockLZ4CompressorOutputStream.java index 15a9cd3a6..50ba00c5a 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 @@ -25,6 +25,7 @@ import java.util.Iterator; import java.util.LinkedList; +import org.apache.commons.compress.compressors.CompressorException; import org.apache.commons.compress.compressors.CompressorOutputStream; import org.apache.commons.compress.compressors.lz77support.LZ77Compressor; import org.apache.commons.compress.compressors.lz77support.Parameters; @@ -361,10 +362,10 @@ public void finish() throws IOException { * @param data The data to fill the window with. * @param off offset of real data into the array. * @param len amount of data. - * @throws IllegalStateException if the stream has already started to write data. + * @throws CompressorException if the stream has already started to write data. * @see LZ77Compressor#prefill */ - public void prefill(final byte[] data, final int off, final int len) { + public void prefill(final byte[] data, final int off, final int len) throws CompressorException { if (len > 0) { final byte[] b = Arrays.copyOfRange(data, off, off + len); compressor.prefill(b); diff --git a/src/main/java/org/apache/commons/compress/compressors/lz77support/LZ77Compressor.java b/src/main/java/org/apache/commons/compress/compressors/lz77support/LZ77Compressor.java index 672ebca6d..2ed3f38a8 100644 --- a/src/main/java/org/apache/commons/compress/compressors/lz77support/LZ77Compressor.java +++ b/src/main/java/org/apache/commons/compress/compressors/lz77support/LZ77Compressor.java @@ -21,6 +21,7 @@ import java.io.IOException; import java.util.Objects; +import org.apache.commons.compress.compressors.CompressorException; import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.ArrayFill; @@ -588,11 +589,11 @@ private int nextHash(final int oldHash, final byte nextByte) { * </p> * * @param data The data to fill the window with. - * @throws IllegalStateException if the compressor has already started to accept data. + * @throws CompressorException if the compressor has already started to accept data. */ - public void prefill(final byte[] data) { + public void prefill(final byte[] data) throws CompressorException { if (currentPosition != 0 || lookahead != 0) { - throw new IllegalStateException("The compressor has already started to accept data, can't prefill anymore"); + throw new CompressorException("The compressor has already started to accept data, can't prefill anymore"); } // don't need more than windowSize for back-references diff --git a/src/test/java/org/apache/commons/compress/compressors/lz77support/LZ77CompressorTest.java b/src/test/java/org/apache/commons/compress/compressors/lz77support/LZ77CompressorTest.java index 624a40cd2..4ddbf96bd 100644 --- a/src/test/java/org/apache/commons/compress/compressors/lz77support/LZ77CompressorTest.java +++ b/src/test/java/org/apache/commons/compress/compressors/lz77support/LZ77CompressorTest.java @@ -28,6 +28,7 @@ import java.util.Arrays; import java.util.List; +import org.apache.commons.compress.compressors.CompressorException; import org.junit.jupiter.api.Test; class LZ77CompressorTest { @@ -238,15 +239,15 @@ void testCantPrefillAfterCompress() throws IOException { final LZ77Compressor c = new LZ77Compressor(newParameters(128), block -> { }); c.compress(Arrays.copyOfRange(BLA, 0, 2)); - assertThrows(IllegalStateException.class, () -> c.prefill(Arrays.copyOfRange(BLA, 2, 4))); + assertThrows(CompressorException.class, () -> c.prefill(Arrays.copyOfRange(BLA, 2, 4))); } @Test - void testCantPrefillTwice() { + void testCantPrefillTwice() throws CompressorException { final LZ77Compressor c = new LZ77Compressor(newParameters(128), block -> { }); c.prefill(Arrays.copyOfRange(BLA, 0, 2)); - assertThrows(IllegalStateException.class, () -> c.prefill(Arrays.copyOfRange(BLA, 2, 4))); + assertThrows(CompressorException.class, () -> c.prefill(Arrays.copyOfRange(BLA, 2, 4))); } @Test
