Verify Kraft's inequality is not violated - #804
Open
fkjellberg wants to merge 1 commit into
Open
Conversation
Generated-by: Claude Opus 5 <noreply@anthropic.com>
garydgregory
requested changes
Aug 17, 2026
garydgregory
left a comment
Member
There was a problem hiding this comment.
Hello @fkjellberg
Thank you for the PR.
A few comments:
- There are no explicit test for a Kraft violation where minCodeLength > 1 or for a violation at a deeper length > 2. The current test only hits length 2.
- The class-level comment could mention “Kraft’s inequality”.
- The exception message could add the offending count and available nodes to aid debugging, but is not required.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Generated-by: Claude Opus 5 noreply@anthropic.com
Thanks for your contribution to Apache Commons! Your help is appreciated!
Before you push a pull request, review this list:
mvn; that'smvnon the command line by itself.The documentation for
HuffmanDecoderstates that the code lengths must not violate Kraft's inequality but this is never checked. It turns out that some of the existing test cases violate this prerequisite.HuffmanDecoderwill now throwCompressorExceptionif the code lengths violate Kraft's inequality. Without this early check before actually start decoding, the decoder may output corrupt data that hopefully will be detected by the CRC checksum or it may throw other unexpected exceptions while decoding the input stream.I used Claude Opus 5 to generate some of the code and to help investigate and fix the failing test cases.
Generated-by: Claude Opus 5 noreply@anthropic.com