Assignment in Conditional Expression
ID |
java.assign_in_condition |
Severity |
high |
Remediation Complexity |
trivial |
Remediation Risk |
low |
Remediation Effort |
low |
Resource |
Reliability |
Language |
Java |
Tags |
CWE:481, reliability, suspicious-comparison |
Rationale
Using = instead of == in a conditional is one of the most common programming mistakes. Even when the assignment is intentional, mixing a side effect into the condition expression makes the code harder to review and more likely to be misread as a comparison.
// Bad - likely meant == instead of =
if (b = true) {
doSomething();
}