Back to all rules
What this rule checks
No null check before instanceof (instanceof is already false for null)
Configuration
When off, this rule is excluded from pipeline runs. Changes apply immediately.
Code Examples
PASS — this code satisfies the rule
class Ball {
  void show() { ellipse(200, 200, 20, 20); }
}
Object thing = new Ball();

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

void draw() {
  if (thing instanceof Ball) {
    ((Ball) thing).show();
  }
}
FAIL — this code triggers the rule
class Ball {
  void show() { ellipse(200, 200, 20, 20); }
}
Object thing = new Ball();

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

void draw() {
  if (thing != null && thing instanceof Ball) {  // instanceof is already false for null
    ((Ball) thing).show();
  }
}
Overview
Category Topic Conditionals
Level Intermediate
Type Built-in PMD
Priority 3 (1 = highest, 5 = lowest)
Status Active
PMD Configuration
PMD reference category/java/design.xml/SimplifyConditional