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 27412912ef0d76c3541a1b0813b20f69876d58d0 Author: Gary Gregory <[email protected]> AuthorDate: Tue Aug 11 14:18:05 2026 -0400 [BZip2] BZip2CompressorOutputStream now throws CompressorException instead of IllegalArgumetException/IllegalStateException. --- src/changes/changes.xml | 3 ++- .../compressors/lz4/BlockLZ4CompressorOutputStream.java | 4 ++-- .../lz4/BlockLZ4CompressorOutputStreamTest.java | 15 ++++++++------- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 2850534aa..ca6c6c6d4 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -68,9 +68,10 @@ The <action> type attribute can be add,update,fix,remove. <action type="fix" dev="ggregory" due-to="Gary Gregory">[7-Zip] SevenZMethodConfiguration now throws ArchiveException instead of IllegalArgumetException/IllegalStateException.</action> <action type="fix" dev="ggregory" due-to="Gary Gregory">[7-Zip] SevenZOutputFile now throws ArchiveException instead of IllegalArgumetException/IllegalStateException.</action> <!-- FIX bzip2 --> - <action type="fix" dev="ggregory" due-to="Tyler Nighswander, Gary Gregory">[BZip2] BZip2CompressorInputStream now throw CompressorException (a subclass of IOException) instead of IllegalArgumetException/IllegalStateException.</action> + <action type="fix" dev="ggregory" due-to="Tyler Nighswander, Gary Gregory">[BZip2] BZip2CompressorInputStream now throws CompressorException instead of IllegalArgumetException/IllegalStateException.</action> <action type="fix" dev="pkarwasz" due-to="Tyler Nighswander, Piotr P. Karwasz">[BZip2] BZip2 input streams treat Huffman codes longer than 20 bits as corrupted data, matching the behavior of the reference implementation.</action> <action type="fix" dev="ggregory" due-to="Gary Gregory, Oti">[BZip2] Fix NullPointerException at BZip2CompressorOutputStream.writeRun() #757.</action> + <action type="fix" dev="ggregory" due-to="Gary Gregory">[BZip2] BZip2CompressorOutputStream now throws CompressorException instead of IllegalArgumetException/IllegalStateException.</action> <!-- FIX dump --> <action type="fix" dev="pkarwasz" due-to="Tyler Nighswander">[Dump] Align DUMP archive block size with Linux `dump` utility.</action> <action type="fix" dev="ggregory" due-to="Tyler Nighswander, Gary Gregory">[Dump] DumpArchiveInputStream.getNextEntry() throws an ArchiveException instead of ArrayIndexOutOfBoundsException.</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 f0b6e2c71..4230a2663 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 @@ -117,9 +117,9 @@ private void prependTo(final Pair other) { } } - void setBackReference(final LZ77Compressor.BackReference block) { + void setBackReference(final LZ77Compressor.BackReference block) throws CompressorException { if (hasBackReference()) { - throw new IllegalStateException(); + throw new CompressorException("back-reference already set"); } brOffset = block.getOffset(); brLength = block.getLength(); diff --git a/src/test/java/org/apache/commons/compress/compressors/lz4/BlockLZ4CompressorOutputStreamTest.java b/src/test/java/org/apache/commons/compress/compressors/lz4/BlockLZ4CompressorOutputStreamTest.java index d9e9eff1f..4a09f6ac8 100644 --- a/src/test/java/org/apache/commons/compress/compressors/lz4/BlockLZ4CompressorOutputStreamTest.java +++ b/src/test/java/org/apache/commons/compress/compressors/lz4/BlockLZ4CompressorOutputStreamTest.java @@ -27,6 +27,7 @@ import java.io.IOException; import java.util.Arrays; +import org.apache.commons.compress.compressors.CompressorException; import org.apache.commons.compress.compressors.lz77support.LZ77Compressor; import org.apache.commons.lang3.ArrayFill; import org.junit.jupiter.api.Disabled; @@ -36,7 +37,7 @@ class BlockLZ4CompressorOutputStreamTest { @Test @Disabled("would pass if the algorithm used for rewriting the final pairs was smarter") - public void canWriteBackReferenceFollowedByShortLiteralIfLengthIsBigEnough() { + public void canWriteBackReferenceFollowedByShortLiteralIfLengthIsBigEnough() throws CompressorException { final BlockLZ4CompressorOutputStream.Pair p = new BlockLZ4CompressorOutputStream.Pair(); p.setBackReference(new LZ77Compressor.BackReference(1, 10)); assertTrue(p.canBeWritten(5)); @@ -44,7 +45,7 @@ public void canWriteBackReferenceFollowedByShortLiteralIfLengthIsBigEnough() { @Test @Disabled("would pass if the algorithm used for rewriting the final pairs was smarter") - public void canWriteBackReferenceFollowedByShortLiteralIfOffsetIsBigEnough() { + public void canWriteBackReferenceFollowedByShortLiteralIfOffsetIsBigEnough() throws CompressorException { final BlockLZ4CompressorOutputStream.Pair p = new BlockLZ4CompressorOutputStream.Pair(); p.setBackReference(new LZ77Compressor.BackReference(10, 4)); assertTrue(p.canBeWritten(5)); @@ -80,21 +81,21 @@ private byte[] prepareExpected(final int length) { } @Test - void testCantWriteBackReferenceFollowedByLiteralThatIsTooShort() { + void testCantWriteBackReferenceFollowedByLiteralThatIsTooShort() throws CompressorException { final BlockLZ4CompressorOutputStream.Pair p = new BlockLZ4CompressorOutputStream.Pair(); p.setBackReference(new LZ77Compressor.BackReference(10, 14)); assertFalse(p.canBeWritten(4)); } @Test - void testCantWriteBackReferenceIfAccumulatedOffsetIsTooShort() { + void testCantWriteBackReferenceIfAccumulatedOffsetIsTooShort() throws CompressorException { final BlockLZ4CompressorOutputStream.Pair p = new BlockLZ4CompressorOutputStream.Pair(); p.setBackReference(new LZ77Compressor.BackReference(1, 4)); assertFalse(p.canBeWritten(5)); } @Test - void testCanWriteBackReferenceFollowedByLongLiteral() { + void testCanWriteBackReferenceFollowedByLongLiteral() throws CompressorException { final BlockLZ4CompressorOutputStream.Pair p = new BlockLZ4CompressorOutputStream.Pair(); p.setBackReference(new LZ77Compressor.BackReference(1, 4)); // a length of 11 would be enough according to the spec, but @@ -123,7 +124,7 @@ void testCanWritePairWithoutLiterals() throws IOException { } @Test - void testPairAccumulatesLengths() { + void testPairAccumulatesLengths() throws CompressorException { final BlockLZ4CompressorOutputStream.Pair p = new BlockLZ4CompressorOutputStream.Pair(); p.setBackReference(new LZ77Compressor.BackReference(1, 4)); final byte[] b = { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; @@ -133,7 +134,7 @@ void testPairAccumulatesLengths() { } @Test - void testPairSeesBackReferenceWhenSet() { + void testPairSeesBackReferenceWhenSet() throws CompressorException { final BlockLZ4CompressorOutputStream.Pair p = new BlockLZ4CompressorOutputStream.Pair(); assertFalse(p.hasBackReference()); p.setBackReference(new LZ77Compressor.BackReference(1, 4));
