java.lang.correctness.assignment-comparison.assignment-comparison

profile photo of semgrepsemgrep
Author
4,989
Download Count*

The value of $X is being ignored and will be used in the conditional test

Run Locally

Run in CI

Defintion

rules:
  - id: assignment-comparison
    message: The value of `$X` is being ignored and will be used in the conditional test
    languages:
      - java
    severity: ERROR
    pattern-either:
      - pattern: if ($X=true) { ... }
      - pattern: if ($X=false) { ... }
    metadata:
      category: correctness
      technology:
        - java
      license: Commons Clause License Condition v1.0[LGPL-2.1-only]

Examples

assignment-comparison.java

class Bar {
    void main() {
        boolean myBoolean;

        //myBoolean == myBoolean;

        // ruleid:assignment-comparison
        if (myBoolean = true) {
            continue;
        }

        // ok:assignment-comparison
        if (myBoolean) {

        }
    }
}