You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug] BitsArray.toString renders an out-of-range padding bit for partial-byte arrays #11462
OpenJDK 1.8.0_302 (GraalVM CE 21.2.0), Maven 3.6.3.
Describe the Bug
When the most significant byte is only partially used, toString() starts at bitLength % Byte.SIZE rather than one less. It renders one extra padding bit, changes the output width and can expose a nonzero bit outside the logical array. Full-byte arrays take another branch and do not expose the problem.
Steps to Reproduce
BitsArrayone = BitsArray.create(1);
one.setBit(0, true);
one.toString(); // "01\n", expected "1\n"BitsArrayseven = BitsArray.create(7);
seven.setByte(0, (byte) 0x80);
seven.toString(); // "10000000\n", expected "0000000\n"BitsArraynine = BitsArray.create(9);
nine.setBit(8, true);
nine.setBit(0, true);
nine.toString(); // extra leading zero, 10 bit characters instead of 9
What Did You Expect to See?
Ignoring the existing newline grouping, exactly bitLength bit characters are rendered, from high logical bit to low logical bit. Padding outside that range is omitted. Whole-byte and zero-length output remain unchanged.
What Did You See Instead?
Every non-byte-aligned positive length renders one extra bit; for a nonzero padding bit the printed result includes data outside the logical array.
Additional Context
A one-line loop-bound correction and four regression methods are prepared. The baseline has 3 failing rendering tests out of 4; all four pass after the fix. An independent Java 8 native filter run executes all 7 filter test classes: 113 tests passed, 0 failures/errors/skips, with Checkstyle and SpotBugs passing.
This differs from #11458 (constructor/clone capacity) and #10506 (position bounds). The regular broker diagnostic caller normally supplies full bytes, so this report concerns the valid partial-byte utility contract rather than an asserted production message failure. Issue/PR and BitsArray discussion searches found no existing rendering fix.
AI assistance: OpenAI Codex was used for investigation, implementation and tests.
The reported issue has been verified against the current codebase on the develop branch.
Root Cause: In BitsArray.toString() (line 239), the loop start index for partial-byte rendering is j = this.bitLength % Byte.SIZE instead of j = this.bitLength % Byte.SIZE - 1. This renders one extra padding bit for non-byte-aligned lengths.
Impact:filter module — BitsArray.toString() output is incorrect for partial-byte arrays. Full-byte arrays are unaffected. BloomFilter diagnostics that rely on this rendering may display misleading output.
Severity: Low — utility rendering method, no broker message-path impact.
Activity
RockteMQ-AI commentedon Oct 20, 2026
Issue Evaluation
Category:
type/bug| Status: ConfirmedThe reported issue has been verified against the current codebase on the
developbranch.Root Cause: In
BitsArray.toString()(line 239), the loop start index for partial-byte rendering isj = this.bitLength % Byte.SIZEinstead ofj = this.bitLength % Byte.SIZE - 1. This renders one extra padding bit for non-byte-aligned lengths.Impact:
filtermodule —BitsArray.toString()output is incorrect for partial-byte arrays. Full-byte arrays are unaffected. BloomFilter diagnostics that rely on this rendering may display misleading output.Severity: Low — utility rendering method, no broker message-path impact.
Verified reproduction:
BitsArray.create(1).setBit(0, true).toString()→"01\n"(expected"1\n")BitsArray.create(9)with bits 0 and 8 set → 10-char output instead of 9A one-line loop-bound correction at line 239 resolves this. An automated fix proposal may be generated. Reply
/approveto proceed with PR generation.Automated evaluation by RockteMQ-AI
[ISSUE apache#11462] Cover partial-byte rendering width and padding