According to the JLS:
"NaN is unordered, so the numerical comparison operators <, <=, >, and >= return false if either or both operands are NaN. The equality operator == returns false if either operand is NaN, and the inequality operator != returns true if either operand is NaN."
...
Code Block | ||
---|---|---|
| ||
public class NaNComparison { public static void main(String[] args) { double result = Double.NaN; if(Double.isNaN(result)) System.out.println("Both are equal"); } } |
Risk Assessment
Comparisons with NaN values may lead to unexpected results.
Rule | Severity | Likelihood | Remediation Cost | Priority | Level |
---|---|---|---|---|---|
EXP01-J | low | unlikely | medium | P?? | L?? |
Automated Detection
TODO
Related Vulnerabilities
Search for vulnerabilities resulting from the violation of this rule on the CERT website.
References
Wiki Markup |
---|
\[[JLS 05|AA. Java References#JLS 05]\] Section 4.2.3 Floating-Point Types, Formats, and |
Findbugs FE: Doomed test for equality to
Values \[[FindBugs 08|AA. Java References#FindBugs 08]\] FE: Doomed test for equality to NaN |