Skip to content

[ISSUE #11462] Exclude padding bits from BitsArray output - #11465

Open
hickey-ai wants to merge 2 commits into
apache:developfrom
hickey-ai:codex/rocketmq-bitsarray-render-20261020
Open

hickey-ai wants to merge 2 commits into
apache:developfrom
hickey-ai:codex/rocketmq-bitsarray-render-20261020

Conversation

@hickey-ai

Copy link
Copy Markdown

Which Issue(s) This PR Fixes

Fixes #11462

Brief Description

The most significant partial byte starts rendering at bitLength % 8, which includes one padding bit outside the logical range. Start at remainder minus one to retain the exact logical width and high-to-low order. Byte-aligned and empty rendering are preserved.

This is independent of the constructor capacity change in #11459 and the earlier index checks in #10506.

How Did You Test This Change?

  • Four new rendering methods cover logical width across eight non-byte-aligned lengths, nonzero padding, partial-byte order, whole-byte arrays and empty arrays. Three methods failed before the correction; all four passed after.
  • Independent Java 8/Maven 3.6.3 run: mvn -B -pl filter -am -Dtest=BitsArrayTest,BitsArrayRenderingTest,BloomFilterTest,ExpressionTest,FilterSpiTest,ParserTest -Dsurefire.failIfNoSpecifiedTests=false -DfailIfNoTests=false test.
  • All 113 tests in the seven filter test classes passed, 0 failures/errors/skips. Checkstyle and SpotBugs passed. Ancestor modules were compiled and checked; their full unit suites were not selected.
  • Entire published Git tree equals the independently tested local tree.

This is a utility rendering contract fix, with no asserted live broker message-loss trigger.

AI assistance: OpenAI Codex was used for investigation, implementation and tests; commits include tooling provenance.

Start the partial-byte print loop at remainder minus one, preserving logical width and bit order.

Generated-by: OpenAI Codex
Cover exact logical width, a nonzero padding bit, bit order, byte-aligned arrays and empty output.

Generated-by: OpenAI Codex

@utafrali utafrali left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The one-character fix (j = this.bitLength % Byte.SIZE - 1) correctly trims the extra padding bit from the most significant partial byte in BitsArray.toString(), preserves the byte-aligned and empty cases (the condition bitLength % Byte.SIZE > 0 keeps the branch inactive for aligned lengths), and the new BitsArrayRenderingTest covers logical width, non-zero padding, high-to-low ordering, and the aligned/empty paths. Minimal, well-scoped bug fix with good test coverage.

@RockteMQ-AI RockteMQ-AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. The fix correctly addresses the off-by-one error in BitsArray.toString() rendering.

Summary

Fixed padding bit rendering in BitsArray.toString() for non-byte-aligned bit lengths.

Analysis

The original code started iteration at j = bitLength % Byte.SIZE, which rendered one extra bit. For a 7-bit array, it would render 8 bits instead of 7. The fix correctly adjusts to j = bitLength % Byte.SIZE - 1, ensuring only the logical number of bits are rendered.

The test coverage is comprehensive, covering various bit lengths (1, 7, 9, 10, 15, 17, 63, 65) and verifying bit ordering in partial bytes.


Automated review by github-manager-bot

@RockteMQ-AI RockteMQ-AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Correct one-line fix — the most significant partial byte was starting at bitLength % 8, which included one padding bit outside the logical range. Starting at bitLength % 8 - 1 retains the exact logical width. The tests cover all edge cases: logical width across 8 non-byte-aligned lengths, padding exclusion, partial-byte bit order, byte-aligned arrays, and empty arrays. Three of the four tests failed before the correction, confirming the fix.


Automated review by github-manager-bot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] BitsArray.toString renders an out-of-range padding bit for partial-byte arrays

3 participants