LogicalAssignment
Assignment where a boolean expression was expected; use == if this assignment wasn't expected or add parentheses for clarity.

Category
JDK
Severity
WARNING
Maturity

The problem

When an assignment expression is used as the condition of a loop, it isn’t clear to the reader whether the assignment was deliberate or it was intended to be an equality test. Parenthesis should be used around assignments in loop conditions to make it clear to the reader that the assignment is deliberate.

That is, instead of this:

void f(boolean x) {
  while (x = checkSomething()) {
    // ...
  }
}

Prefer while ((x = checkSomething())) { or while (x == checkSomething()) {.

Suppression

Suppress false positives by adding an @SuppressWarnings("LogicalAssignment") annotation to the enclosing element.