pulsar icon indicating copy to clipboard operation
pulsar copied to clipboard

[Bug] LongBitmap.previousAbsentValue throws AssertionError when the sentinel aliases MAX_UINT32

Open void-ptr974 opened this issue 1 month ago • 2 comments

Search before reporting

  • [x] I searched existing issues and pull requests and did not find a report of this reproduction.

User environment

  • Apache Pulsar master checkout: 633511a812f4607a8d10c62ab4c8c50de36ae1ad.
  • The relevant production implementation, interface and dependency version file are unchanged at the subsequently fetched origin/master commit 0dfc5d88dcff93c9eaffff71f3eef6e91f22ad84.
  • RoaringBitmap 1.6.20; Temurin OpenJDK 25.0.2; macOS x86_64.
  • Reproduced against unchanged production sources at the component level. Released Pulsar versions were not evaluated.

Issue description

A valid LongBitmap.previousAbsentValue(0) query throws AssertionError when dependency assertions are enabled and the bitmap contains both 0 and 0xffffffffL.

The documented result is -1: there is no absent value in the supported nonnegative domain less than or equal to zero when zero is present.

Reproducing the issue

Add this method to the existing pulsar-common/src/test/java/org/apache/pulsar/common/util/collections/LongBitmapTest.java, together with import static org.assertj.core.api.Assertions.assertThat;:

@Test
public void testPreviousAbsentDoesNotConfuseSentinelWithMaxUint32() {
    LongBitmap bitmap = LongBitmaps.create();
    bitmap.add(0);
    bitmap.add(0xffff_ffffL);

    assertThat(bitmap.previousAbsentValue(0)).isEqualTo(-1);
}

Run with the normal Gradle test JVM, which enables assertions:

./gradlew :pulsar-common:test \
  --tests 'org.apache.pulsar.common.util.collections.LongBitmapTest.testPreviousAbsentDoesNotConfuseSentinelWithMaxUint32' \
  -PtestRetryCount=0

Expected: the query returns -1 without throwing.

Actual:

java.lang.AssertionError
    at org.roaringbitmap.RoaringBitmap.previousAbsentValue(RoaringBitmap.java:2994)
    at org.apache.pulsar.common.util.collections.ConcurrentRoaringBitmap.previousAbsentValue(ConcurrentRoaringBitmap.java:301)

The same minimal Pulsar API calls in an independent Java main give:

JVM option Result
-ea AssertionError
-da Correctly returns -1

The query that reproduces this is previousAbsentValue(0). Merely adding the maximum uint32 value and querying previousAbsentValue(0xffffffffL) does not reproduce it.

Additional information and impact

Are you willing to submit a PR?

  • [ ] I'm willing to submit a PR!

void-ptr974 avatar Oct 24 '26 03:10 void-ptr974

Anyone is welcome to pick this up and submit a fix. Please leave a comment here if you'd like to work on it so contributors can coordinate.

void-ptr974 avatar Oct 24 '26 03:10 void-ptr974

I'd like to work on this together with #27088.

RoaringBitmap.previousAbsentValue(int) uses -1 as its "not found" sentinel, which aliases 0xFFFFFFFF in the unsigned domain. When 0 is present, the wrapper should return -1 without relying on that ambiguous sentinel. I'll add the reproduction as a regression test and run it with assertions enabled.

LiuYC3213687107 avatar Oct 24 '26 15:10 LiuYC3213687107