[Bug] LongBitmap.previousAbsentValue throws AssertionError when the sentinel aliases MAX_UINT32
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/mastercommit0dfc5d88dcff93c9eaffff71f3eef6e91f22ad84. - RoaringBitmap
1.6.20; Temurin OpenJDK25.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
- The interface explicitly supports the uint32 domain and the -1 absent-value sentinel.
- The wrapper delegates to RoaringBitmap.previousAbsentValue((int) from).
- Inspection of the RoaringBitmap 1.6.20 bytecode shows that its assertion tests membership after casting the returned value to int, without excluding the
-1sentinel. The cast aliases the unsigned maximum value, which is present in this reproduction. - This is an assertion-enabled API failure. With assertions disabled, the result in this reproduction is correct. Pulsar's checked default launch scripts do not add
-ea; no broker-level failure under default launch settings or message loss has been established.
Are you willing to submit a PR?
- [ ] I'm willing to submit a PR!
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.
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.