Back to all rules
What this rule checks
No assignments inside expressions
Configuration
When off, this rule is excluded from pipeline runs. Changes apply immediately.
Code Examples
PASS — this code satisfies the rule
int score = 0;

void setup() {
  size(400, 400);
}

void draw() {
  background(255);
  score = score + 1;
  if (score > 100) {
    score = 0;
  }
  text(score, 20, 20);
}
FAIL — this code triggers the rule
int score = 0;

void setup() {
  size(400, 400);
}

void draw() {
  background(255);
  if ((score = score + 1) > 100) {  // assignment hidden in the condition
    score = 0;
  }
  text(score, 20, 20);
}
Overview
Category Topic Conditionals
Level Advanced
Type Built-in PMD
Priority 3 (1 = highest, 5 = lowest)
Status Active
PMD Configuration
PMD reference category/java/errorprone.xml/AssignmentInOperand