FP for BigInteger constructor

48 views
Skip to first unread message

frank.re...@googlemail.com

unread,
Apr 18, 2018, 6:37:02 AM4/18/18
to SonarQube
Hi

SonarJava gives me squid:S2129
Constructors should not be used to instantiate "String", "BigInteger", "BigDecimal" and primitive-wrapper classes

for this code:
String value = ...;
new BigInteger( value );

But there is no .valueOf which takes a string, only long. And the string might have a number exceeding a long.
Hence I think this is a false positive.
Workaround for me is, to change it to:

new BigInteger( value, 10 );

Regards
Frank Benoit
Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted

Jerome Boccard

unread,
May 2, 2018, 4:41:52 AM5/2/18
to SonarQube
Hello Frank,

Thank you for your feedback.
Yes you are right, this is indeed a case of false positive.

We created a corresponding Jira ticket, which you can find here: https://jira.sonarsource.com/browse/SONARJAVA-2740.

Thank you.

Kind regards,
Reply all
Reply to author
Forward
0 new messages