Skip to content

[ISSUE #11458] Fix BitsArray backing capacity validation - #11459

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

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

Conversation

@hickey-ai

Copy link
Copy Markdown

Which Issue(s) This PR Fixes

Fixes #11458

Brief Description

Correct the reversed capacity comparison in the byte-array constructor. Valid partial-byte arrays can be reconstructed and cloned, while logical bit lengths beyond the backing storage are rejected. Use a long capacity calculation and retain the existing null/empty/non-positive checks and defensive copying.

Update two tests that encoded the reversed capacity expectations and add one clone regression covering nine bit lengths, retained contents, independent storage and logical bounds. This is separate from the index-bound changes in #10506.

How Did You Test This Change?

  • Exact-source utility suite: 28 tests, 3 failing before the fix, all 28 passing after on Java 8 and Java 21.
  • Native Java 8/Maven 3.6.3: mvn -B -pl filter -am -Dtest=BitsArrayTest,BloomFilterTest,ExpressionTest,FilterSpiTest,ParserTest -Dsurefire.failIfNoSpecifiedTests=false -DfailIfNoTests=false test
  • All 110 filter tests passed, with 0 failures/errors/skips; Checkstyle and SpotBugs passed for the reactor code modules. Ancestor modules were compiled and checked, their full unit suites were not selected.
  • The published branch Git tree was compared with the tested local tree and is identical.

No live broker or message-loss reproduction is claimed; BloomFilter normally rounds to whole bytes.

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

Reject logical lengths beyond backing storage and allow valid partial-byte arrays. Regression coverage follows in this branch.

Generated-by: OpenAI Codex
Correct two inverted capacity expectations and cover independent clone storage across nine bit lengths.

Generated-by: OpenAI Codex

@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. This is a critical bug fix — the original validation was inverted.

Summary

Fixed the backing capacity validation in BitsArray constructor: the comparison direction was reversed, rejecting valid inputs and accepting invalid ones.

Analysis

Original bug:

if (bitLength < bytes.length * Byte.SIZE) {  // WRONG: rejects valid cases
    throw new IllegalArgumentException(...);
}

This rejected valid cases (e.g., 10-bit array backed by 2 bytes) and accepted invalid cases (e.g., 20-bit array backed by 1 byte).

Fix:

if (bitLength > (long) bytes.length * Byte.SIZE) {  // CORRECT
    throw new IllegalArgumentException(...);
}

The fix also adds (long) cast to prevent integer overflow for large byte arrays.

The updated tests correctly verify both valid and invalid cases. The clone test ensures independent storage and partial byte length preservation.


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 rejects partial-byte clones but accepts bit lengths beyond backing capacity

2 participants