Back to all rules
What this rule checks
Avoids deeply nested conditionals (3+ levels)
Configuration
When off, this rule is excluded from pipeline runs. Changes apply immediately.
Code Examples
PASS — this code satisfies the rule
void setup() {
  size(400, 400);
}

void draw() {
  background(255);
  if (mousePressed && mouseX > 200 && mouseY > 200) {
    fill(255, 0, 0);
  }
  rect(200, 200, 200, 200);
}
FAIL — this code triggers the rule
void setup() {
  size(400, 400);
}

void draw() {
  background(255);
  if (mousePressed) {
    if (mouseX > 200) {
      if (mouseY > 200) {  // three ifs deep
        fill(255, 0, 0);
      }
    }
  }
  rect(200, 200, 200, 200);
}
Overview
Category Topic Conditionals
Level Advanced
Type Built-in PMD
Priority 3 (1 = highest, 5 = lowest)
Status Active
PMD Configuration
PMD reference category/java/design.xml/AvoidDeeplyNestedIfStmts