commons-configuration icon indicating copy to clipboard operation
commons-configuration copied to clipboard

Configuration-766: BigDecimal(double) should not be used.

Open HarisAdzemovic opened this issue 4 years ago • 8 comments

Because of floating point imprecision, you're unlikely to get the value you expect from the BigDecimal(double) constructor. See https://rules.sonarsource.com/java/type/Bug/RSPEC-2111.

HarisAdzemovic avatar Oct 29 '19 10:10 HarisAdzemovic

@HarisAdzemovic May you please rebase on master? We can then get the CI builds to re-run. TY!

garydgregory avatar Aug 20 '20 15:08 garydgregory

Rebased, but looks like we had a test verifying the old behavior

[ERROR] TestPropertyConverter.testToBigDecimalDoubleConstructor:68 Incorrect BigDecimal value expected:<0.1000000000000000055511151231257827021181583404541015625> but was:<0.1>

As mentioned in the JIRA issue comments.

kinow avatar Aug 21 '20 01:08 kinow

I applied @aherbert's suggestion in his last comment in CONFIGURATION-766 locally, and it worked with no issues. That approach looks good to me, modifying the toBigDecimal in PropertyConverter. @HarisAdzemovic if you update the unit tests to use BigDecimal.valueOf(d) instead of new BigDecimal(d) and then apply @aherbert 's patch, this PR should be ready to be merged IMO.

kinow avatar Aug 21 '20 02:08 kinow

@HarisAdzemovic May you please rebase on master?

garydgregory avatar Jun 26 '21 15:06 garydgregory

@HarisAdzemovic May you please rebase on master?

garydgregory avatar Mar 03 '22 02:03 garydgregory

Rebased. See my previous comment on the patch from JIRA and updating the tests too :+1:

kinow avatar May 10 '22 05:05 kinow

Let's rebase this again since we have red builds.

garydgregory avatar May 15 '22 18:05 garydgregory

Ping

garydgregory avatar Jul 14 '22 14:07 garydgregory

@HarisAdzemovic ping

garydgregory avatar Nov 06 '22 19:11 garydgregory