commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Haris Adzemovic (Jira)" <>
Subject [jira] [Commented] (CONFIGURATION-766) BigDecimal(double) should not be used
Date Tue, 29 Oct 2019 12:04:00 GMT


Haris Adzemovic commented on CONFIGURATION-766:

Thanks, Alex, that works wonderfully.

I also failed a test inĀ testNumberConversions() with the error that "42" != "42.0":
assertEquals("Wrong DigDecimal returned", new BigDecimal("42"), config .getBigDecimal(KEY_NUMBER));
The reason is that the .equals() method of BigDecimal, when comparing two BigDecimals, not
only compares the numeric value but also their scale. Meanwhile, toBigDecimal makes the conversion
Number.doubleValue() which will always return a number with one decimal (42.0).

So I wonder if it would be acceptable to change the test to "42.0" or if I should expand it
to use the compareTo method and make sure that the numeric difference is 0?

> BigDecimal(double) should not be used
> -------------------------------------
>                 Key: CONFIGURATION-766
>                 URL:
>             Project: Commons Configuration
>          Issue Type: Bug
>         Environment: A single occurrence in file, line 393:
> {code:java}
> return new BigDecimal(n.doubleValue());
> {code}
>            Reporter: Haris Adzemovic
>            Priority: Minor
> Static analysis with SonarQube shows a violation of ruleĀ [S2111|[]]
- a dangerous use of the BigDecimal constructor.
> Fixed by using BigDecimal.valueOf(param) instead.

This message was sent by Atlassian Jira

View raw message