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


The following commit(s) were added to refs/heads/master by this push:
     new c3fef93f3 Remove unnecessary parameter from HuffmanDecoder public 
constructor (#796)
c3fef93f3 is described below

commit c3fef93f30f225936f75ffc0758f776c37037bbc
Author: Fredrik Kjellberg <[email protected]>
AuthorDate: Sat Aug 8 23:15:06 2026 +0200

    Remove unnecessary parameter from HuffmanDecoder public constructor (#796)
---
 .../bzip2/BZip2CompressorInputStream.java          |  2 +-
 .../commons/compress/huffman/HuffmanDecoder.java   | 26 +++++++++-------------
 .../compress/huffman/HuffmanDecoderTest.java       |  2 +-
 3 files changed, 13 insertions(+), 17 deletions(-)

diff --git 
a/src/main/java/org/apache/commons/compress/compressors/bzip2/BZip2CompressorInputStream.java
 
b/src/main/java/org/apache/commons/compress/compressors/bzip2/BZip2CompressorInputStream.java
index 6e8eee45e..772cd3761 100644
--- 
a/src/main/java/org/apache/commons/compress/compressors/bzip2/BZip2CompressorInputStream.java
+++ 
b/src/main/java/org/apache/commons/compress/compressors/bzip2/BZip2CompressorInputStream.java
@@ -270,7 +270,7 @@ static void recvDecodingTables(final BitInputStream bin, 
final Data dataShadow)
             }
             try {
                 // Same limits as in the reference C implementation of bzip2
-                dataShadow.huffmanDecoders[t] = new 
HuffmanDecoder(codeLengths, alphaSize, 1, MAX_CODE_LEN);
+                dataShadow.huffmanDecoders[t] = new 
HuffmanDecoder(codeLengths, 1, MAX_CODE_LEN);
             } catch (final IllegalArgumentException e) {
                 throw new CompressorException("Invalid Huffman data: " + 
e.getMessage(), e);
             }
diff --git 
a/src/main/java/org/apache/commons/compress/huffman/HuffmanDecoder.java 
b/src/main/java/org/apache/commons/compress/huffman/HuffmanDecoder.java
index 6ac24f2c4..71b336f02 100644
--- a/src/main/java/org/apache/commons/compress/huffman/HuffmanDecoder.java
+++ b/src/main/java/org/apache/commons/compress/huffman/HuffmanDecoder.java
@@ -88,7 +88,7 @@ public final class HuffmanDecoder {
      * @throws IllegalArgumentException if any code length is out of range [0, 
30].
      */
     public HuffmanDecoder(final int[] codeLengths) {
-        this(codeLengths, codeLengths.length, 0, MAX_SUPPORTED_CODE_LENGTH);
+        this(codeLengths, 0, MAX_SUPPORTED_CODE_LENGTH);
     }
 
     /**
@@ -99,28 +99,24 @@ public HuffmanDecoder(final int[] codeLengths) {
      * </p>
      *
      * @param codeLengths    code length per symbol; {@code 0} means the 
symbol is not used; not {@code null}.
-     * @param codeLengthSize number of symbols to read from {@code 
codeLengths} (must be {@code > 0} and {@code <= codeLengths.length}).
      * @param minCodeLength  minimum allowed code length present in {@code 
codeLengths}.
      * @param maxCodeLength  maximum allowed code length present in {@code 
codeLengths}.
      * @throws NullPointerException     if {@code codeLengths} is {@code null}.
-     * @throws IllegalArgumentException if {@code codeLengthSize} is out of 
range, if any code length is out of range or if {@code maxCodeLength} exceeds 
the
+     * @throws IllegalArgumentException if {@code codeLengths} size is out of 
range, if any code length is out of range or if {@code maxCodeLength} exceeds 
the
      *                                  implementation limit (30).
      */
-    public HuffmanDecoder(final int[] codeLengths, final int codeLengthSize, 
final int minCodeLength, final int maxCodeLength) throws 
IllegalArgumentException {
+    public HuffmanDecoder(final int[] codeLengths, final int minCodeLength, 
final int maxCodeLength) throws IllegalArgumentException {
         Objects.requireNonNull(codeLengths, "codeLengths");
         if (maxCodeLength > MAX_SUPPORTED_CODE_LENGTH) {
             throw new IllegalArgumentException(String.format("maxCodeLength 
(%d) exceeds supported limit (%d)", maxCodeLength, MAX_SUPPORTED_CODE_LENGTH));
         }
-        if (codeLengthSize <= 0) {
-            throw new IllegalArgumentException(String.format("codeLengthSize 
must be > 0; was %d", codeLengthSize));
-        }
-        if (codeLengths.length < codeLengthSize) {
-            throw new IllegalArgumentException(String.format("codeLengthSize 
(%d) exceeds codeLengths.length (%d)", codeLengthSize, codeLengths.length));
+        if (codeLengths.length <= 0) {
+            throw new IllegalArgumentException(String.format("codeLengthSize 
must be > 0; was %d", codeLengths.length));
         }
         // Validate and find min/max lengths
         int min = maxCodeLength;
         int max = minCodeLength;
-        for (int i = 0; i < codeLengthSize; i++) {
+        for (int i = 0; i < codeLengths.length; i++) {
             final int len = codeLengths[i];
             if (len < minCodeLength || len > maxCodeLength) {
                 throw new IllegalArgumentException(
@@ -141,9 +137,9 @@ public HuffmanDecoder(final int[] codeLengths, final int 
codeLengthSize, final i
         // Allocate outputs; we reuse them as scratch inside fillCodeTable
         this.bias = new int[max + 1];
         this.limit = new int[max + 1];
-        this.sorted = new int[codeLengthSize];
+        this.sorted = new int[codeLengths.length];
         // Arrays are zero-initialized; no additional temps needed.
-        fillCodeTable(codeLengths, minLength, max, codeLengthSize, bias, 
limit, sorted);
+        fillCodeTable(codeLengths, minLength, max, bias, limit, sorted);
     }
 
     /**
@@ -167,11 +163,11 @@ public int getMaxLength() {
     /**
      * Builds canonical decode tables.
      */
-    private static void fillCodeTable(final int[] codeLengths, final int 
minLen, final int maxLen, final int codeLengthSize, final int[] bias,
+    private static void fillCodeTable(final int[] codeLengths, final int 
minLen, final int maxLen, final int[] bias,
             final int[] limit, final int[] sorted) {
         // 1) Histogram of code lengths
         final int[] count = new int[maxLen + 1];
-        for (int symbol = 0; symbol < codeLengthSize; symbol++) {
+        for (int symbol = 0; symbol < codeLengths.length; symbol++) {
             final int len = codeLengths[symbol];
             if (len == 0) {
                 continue;
@@ -187,7 +183,7 @@ private static void fillCodeTable(final int[] codeLengths, 
final int minLen, fin
         }
         // 3) Build table of symbols sorted by length, then by symbol
         // Adjust offsets to point to the last element of each length
-        for (int symbol = 0; symbol < codeLengthSize; symbol++) {
+        for (int symbol = 0; symbol < codeLengths.length; symbol++) {
             final int len = codeLengths[symbol];
             if (len == 0) {
                 continue;
diff --git 
a/src/test/java/org/apache/commons/compress/huffman/HuffmanDecoderTest.java 
b/src/test/java/org/apache/commons/compress/huffman/HuffmanDecoderTest.java
index 898656bd3..0be3bb578 100644
--- a/src/test/java/org/apache/commons/compress/huffman/HuffmanDecoderTest.java
+++ b/src/test/java/org/apache/commons/compress/huffman/HuffmanDecoderTest.java
@@ -47,7 +47,7 @@ void testCreateHuffmanDecodingTablesWithLargeAlphaSize() {
             // Use all code lengths within valid range [1, 20]
             codeLengths[i] = (char) (i % 20 + 1);
         }
-        final HuffmanDecoder decoder = assertDoesNotThrow(() -> new 
HuffmanDecoder(codeLengths, codeLengths.length, 1, 20),
+        final HuffmanDecoder decoder = assertDoesNotThrow(() -> new 
HuffmanDecoder(codeLengths, 1, 20),
                 "HuffmanDecoder constructor should not throw for valid 
codeLengths array of MAX_ALPHA_SIZE");
         assertEquals(decoder.getMinLength(), 1, "Minimum code length should be 
1");
         assertEquals(decoder.getMaxLength(), 20, "Maximum code length should 
be 20");

Reply via email to