FN in S2111: Autoboxing confuses bug detection of new BigDecimal( double )

For some reason the rule java:S2111 did not detect the following issue:

Object myDoubleObject = 23.5d;
new BigDecimal((Double)myDoubleObject)

However, when i change it to the following the issue is detected correctly:

Object myDoubleObject = 23.5d;
new BigDecimal((double)(Double)myDoubleObject)

SonarQube Version:
SQUID: https://rules.sonarsource.com/java/RSPEC-2111

I hope this is not expected behaviour :wink:

Hello @schwaller,

I agree with you and this is not an expected behavior.
In fact, it seems that BigDecimal created from boxed types are not detected, but still subject to the problem.

Ticket created (SONARJAVA-3455).


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.