pulsar
pulsar copied to clipboard
fix: round relative time seconds exactly
Motivation
RelativeTimeUtil.nsToSeconds currently builds a BigDecimal from a double. For half-up rounding cases such as 1.2345 seconds, the binary double value can be slightly below the decimal half and round down unexpectedly.
Modifications
- Convert nanoseconds with BigDecimal.valueOf(ns, 9) so the decimal value is exact before rounding.
- Apply the same fix to both common and cli-utils RelativeTimeUtil implementations.
- Add coverage for a half-up rounding boundary.
Verifications
- git diff --check
- Not run: ./gradlew :pulsar-common:test --tests "org.apache.pulsar.common.util.RelativeTimeUtilTest" -PtestRetryCount=0 (local environment has no Java Runtime)