Back to all rules
What this rule checks
Declares at least one local variable with an initializer
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);
  float diameter = 40;
  if (mousePressed) {
    diameter = 80;
  }
  ellipse(mouseX, mouseY, diameter, diameter);
}
FAIL — this code triggers the rule
void setup() {
  size(400, 400);
}

void draw() {
  background(255);
  float diameter;  // declared without a starting value
  if (mousePressed) {
    diameter = 80;
  } else {
    diameter = 40;
  }
  ellipse(mouseX, mouseY, diameter, diameter);
}
Overview
Category Topic Variables
Level Basic
Type Custom Zita
Priority 3 (1 = highest, 5 = lowest)
Status Active
PMD Configuration
Java class nl.utwente.processing.pmd.rules.LocalVarInitRule
Message template No local variable is declared with an initializer.