...
Comparisons with NaN values can lead to unexpected results.
Rule | Severity | Likelihood | Detectable | RepairableRemediation Cost | Priority | Level |
|---|---|---|---|---|---|---|
NUM07-J | Low | Probable | Yes | YesMedium | P4P6 | L3L2 |
Automated Detection
Automated detection of comparison with NaN is straightforward. Sound determination of whether the possibility of an unordered result has been correctly handled is not feasible in the general case. Heuristic checks could be useful.
| Tool | Version | Checker | Description | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Klocwork |
| JAVA.COMPARE.NAN | CodeSonar | PMD.Design.BadComparison FB.CORRECTNESS.FE_TEST_IF_EQUAL_TO_NOT_A_NUMBER | Bad comparison Doomed test for equality to NaN | |||||||
| Parasoft Jtest |
| PBCERT. | NUMNUM07.NAN | Avoid comparisons to Double.NaN or Float.NaN | ||||||||
| PVS-Studio |
| V6038 |
Bibliography
[JLS 2015] | |
| [Seacord 2015] | NUM07-J. Do not attempt comparisons with NaN LiveLesson |
...