I’m using sonar-scanner 4.2 to publish report into sonarQube community 8.9.2 with sbt-scoverage 1.6.1 in a scala project
1 reported bug was about rule scala:S1764 Identical expressions should not be used on both sides of a binary operator
The code was something like this : java.text.NumberFormat.getCurrencyInstance(“whatever”).parse(text).filter(num => num == num) which should return a Number
Obviously, the code is quite peculiar, but I didn’t find any other workaround for the spcefic bug we had in production: when the text input has a strange character, the num is a Number.NaN, and I need to filter it out because making operation on this Number will throw an exception. The only solution I found was on Scala Best Practices - Use isNaN when checking for NaN which propose the fast solution of comparing the number to itself since all NaN are different and it will thus return false.
Also, it’s a Number, not a Double, so I can’t use Double.isNan?
Well, it’s either a false positive (abeit in rare case) or there is a better workaround, but I didn’t find any thing elegant. Should I box the value? What should be the most maintenable code for this case?
Thanks for any tips.