No rule to check for incorrect cast from one numeric data type to another

java
javascript

(Ankur) #1

SonarQube 6.7.4.

I cannot find any rule which could alert of an incorrect cast from one numeric data type to another. Such a cast (e.g. from float to int, int to short) may cause loss of precision and cause unexpected behavior.

This is also documented in CWE-681.

There are other cast related rules available (e.g. Redundant casts should not be used, Math operands should be cast before assignment), but they do not cover this behavior.