Back to all rules
What this rule checks
No class assigns to a global variable from the main tab
Configuration
When off, this rule is excluded from pipeline runs. Changes apply immediately.
Code Examples
PASS — this code satisfies the rule
int score = 0;
Ball ball = new Ball();

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

void draw() {
  background(255);
  if (ball.move()) {
    score++;  // the main tab updates its own global
  }
  ellipse(ball.x, 200, 20, 20);
}

class Ball {
  float x = 0;
  boolean move() {
    x = (x + 3) % width;
    return x < 3;
  }
}
FAIL — this code triggers the rule
int score = 0;
Ball ball = new Ball();

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

void draw() {
  background(255);
  ball.move();
  ellipse(ball.x, 200, 20, 20);
}

class Ball {
  float x = 0;
  void move() {
    x = (x + 3) % width;
    if (x < 3) {
      score++;  // the class changes a global
    }
  }
}
Overview
Category PDPS
Type Custom Zita
Priority 3 (1 = highest, 5 = lowest)
Status Active
PMD Configuration
Java class nl.utwente.processing.pmd.rules.OutOfScopeStateChangeRule
Message template Do not change variable {0} in the {1}.