lhotari opened a new issue, #21108: URL: https://github.com/apache/pulsar/issues/21108
### Search before asking - [X] I searched in the [issues](https://github.com/apache/pulsar/issues) and found nothing similar. ### Version any ### Minimal reproduce step The `signSafeMod` function used in Pulsar collection classes doesn't work with negative input values. This impacts the hash bucket algorithm. ``` static final int signSafeMod(long n, int max) { return (int) (n & (max - 1)) << 2; } ``` Demonstration in `jshell` with the invalid `signSafeMod` implementation: ``` jshell> static final int signSafeMod(long n, int max) { ...> return (int) (n & (max - 1)) << 2; ...> } | created method signSafeMod(long,int) jshell> signSafeMod(-2, 8) $2 ==> 24 ``` The correct value for signSafeMod(-2, 8) is `6`, not `24`. ### What did you expect to see? `signSafeMod` function used should really be sign safe and work correctly with negative input values. ### What did you see instead? This bug wastes CPU cycles because of the inefficient storage and retrieval since collisions will be very likely when the used capacity of the collection implementation increases. ### Anything else? _No response_ ### Are you willing to submit a PR? - [X] I'm willing to submit a PR! -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
