Back to all rules
What this rule checks
Declares at least one global variable with an initializer (e.g. int score = 0, not just int score)
Configuration
When off, this rule is excluded from pipeline runs. Changes apply immediately.
Code Examples
PASS — this code satisfies the rule
int score = 0;  // starting value given at the declaration

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

void draw() {
  background(255);
  fill(0);
  text("Score: " + score, 20, 30);
}

void mousePressed() {
  score = score + 1;
}
FAIL — this code triggers the rule
int score;  // declared without a starting value

void setup() {
  size(400, 400);
  score = 0;
}

void draw() {
  background(255);
  fill(0);
  text("Score: " + score, 20, 30);
}

void mousePressed() {
  score = score + 1;
}
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.GlobalVarInitRule
Message template No global variable is declared with an initializer.