commons-configuration
commons-configuration copied to clipboard
Configuration-766: BigDecimal(double) should not be used.
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 May you please rebase on master? We can then get the CI builds to re-run. TY!
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.
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.
@HarisAdzemovic May you please rebase on master?
@HarisAdzemovic May you please rebase on master?
Rebased. See my previous comment on the patch from JIRA and updating the tests too :+1:
Let's rebase this again since we have red builds.
Ping
@HarisAdzemovic ping