[
https://issues.apache.org/jira/browse/CONFIGURATION-766?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16961890#comment-16961890
]
Alex Herbert commented on CONFIGURATION-766:
--------------------------------------------
Just write the same test targeting the method in PropertyConverter. This
currently fails:
{code:java}
/**
* Tests conversion to BigDecimal avoids the use of the BigDecimal constructor
using a double.
*/
@Test
public void testToBigDecimal()
{
// If the conversion uses new BigDecimal(0.1) the result is not exact due
to round off.
// The result is 0.1000000000000000055511151231257827021181583404541015625.
// See Sonar rule: https://rules.sonarsource.com/java/type/Bug/RSPEC-2111
final double d = 0.1;
assertEquals("Incorrect BigDecimal value", new
BigDecimal(Double.toString(d)),
PropertyConverter.toBigDecimal(d));
}
{code}
> BigDecimal(double) should not be used
> -------------------------------------
>
> Key: CONFIGURATION-766
> URL: https://issues.apache.org/jira/browse/CONFIGURATION-766
> Project: Commons Configuration
> Issue Type: Bug
> Environment: A single occurrence in file PropertyConverter.java, 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|[https://rules.sonarsource.com/java/type/Bug/RSPEC-2111]] - a
> dangerous use of the BigDecimal constructor.
> Fixed by using BigDecimal.valueOf(param) instead.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)