error-prone icon indicating copy to clipboard operation
error-prone copied to clipboard

Fix BigDecimalLiteralDouble for boxed floating-point values

Open codingkiddo opened this issue 6 months ago • 2 comments

Fixes #5759.

Summary

BigDecimalLiteralDouble reported precision-loss diagnostics for direct double / float literals passed to BigDecimal(double), but it missed boxed Double / Float values.

For example:

Double boxedD = 0.1;
new BigDecimal(boxedD);

This still invokes the BigDecimal(double) constructor after unboxing, so it has the same precision-loss problem as passing a primitive floating-point literal directly.

Changes

  • Added regression coverage for boxed Double / Float arguments.
  • Updated BigDecimalLiteralDouble to detect boxed floating-point arguments consistently with primitive floating-point arguments.
  • Kept the existing suggested fix behavior limited to direct literal cases, where the replacement source is safe to construct.

Test

mvn -pl core -Dtest=BigDecimalLiteralDoubleTest test

Result:

Tests run: 3, Failures: 0, Errors: 0, Skipped: 0
BUILD SUCCESS

codingkiddo avatar May 09 '26 08:05 codingkiddo

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

google-cla[bot] avatar May 09 '26 08:05 google-cla[bot]

Thanks. I have signed/updated the Google CLA check.

One note on the implementation: the diagnostic is intentionally extended to boxed Double / Float arguments because overload resolution still selects BigDecimal(double) after unboxing. The suggested fix remains limited to direct literal/unary literal cases because only those have safe replacement source available. For boxed or variable arguments, the PR reports the precision-loss risk without offering an automatic replacement.

codingkiddo avatar May 26 '26 08:05 codingkiddo

Gentle ping.

The Google CLA is resolved now, and the PR includes regression coverage for #5759.

I noticed the required “GitHub Actions Scan” check is still waiting to run. Please let me know if any maintainer action is needed to trigger it, or if you would prefer any changes to the implementation.

Happy to adjust.

codingkiddo avatar Sep 26 '26 02:09 codingkiddo