title: VariableListener corruption
body: <p>I was playing around with the custom shadow variables and custom variable listeners. I found that the "Exam timetabling" example uses custom shadow variables to update "Following exams" when the "Leading Exam" changes.
  So what i did to assert asking in this question was true <a href="https://stackoverflow.com/questions/36538367/custom-variablelistener-updating-more-than-one-shadow-variables/36543908#36543908">Custom VariableListener updating more than one shadow variables</a> i added a second shadow variable in the Following Exam class which references the variable "period" , and then in the variable listener of the LeadingExam planning entity(PeriodUpdatingVariableListener) i update both the variables.</p>
  
  <p>Here is the code for the "FollowingExam" class</p>
  
  <pre><code>@PlanningEntity
  @XStreamAlias("FollowingExam")
  public class FollowingExam extends Exam {
  
  protected LeadingExam leadingExam;
  
  // Shadow variables
  protected Period period;
  protected Integer var;
  
  @CustomShadowVariable(variableListenerClass = PeriodUpdatingVariableListener.class, sources = {
          @CustomShadowVariable.Source(entityClass = LeadingExam.class, variableName = "period") })
  public Period getPeriod() {
      return period;
  }
  
  public void setPeriod(Period period) {
      this.period = period;
  }
  
  @CustomShadowVariable(variableListenerRef = @PlanningVariableReference(variableName = "period"))
  public Integer getVar() {
      return var;
  }
  
  public void setVar(Integer var) {
      this.var = var;
  }
  
  public LeadingExam getLeadingExam() {
      return leadingExam;
  }
  
  public void setLeadingExam(LeadingExam leadingExam) {
      this.leadingExam = leadingExam;
  }
  
  }
  </code></pre>
  
  <p>And in the "PeriodUpdatingVariableListener" i have the next code</p>
  
  <pre><code>public class PeriodUpdatingVariableListener implements VariableListener&lt;LeadingExam&gt; {
  
  public void beforeEntityAdded(ScoreDirector scoreDirector, LeadingExam leadingExam) {
      // Do nothing
  }
  
  public void afterEntityAdded(ScoreDirector scoreDirector, LeadingExam leadingExam) {
      updatePeriod(scoreDirector, leadingExam);
  }
  
  public void beforeVariableChanged(ScoreDirector scoreDirector, LeadingExam leadingExam) {
      // Do nothing
  }
  
  public void afterVariableChanged(ScoreDirector scoreDirector, LeadingExam leadingExam) {
      updatePeriod(scoreDirector, leadingExam);
  }
  
  public void beforeEntityRemoved(ScoreDirector scoreDirector, LeadingExam leadingExam) {
      // Do nothing
  }
  
  public void afterEntityRemoved(ScoreDirector scoreDirector, LeadingExam leadingExam) {
      // Do nothing
  }
  
  protected void updatePeriod(ScoreDirector scoreDirector, LeadingExam leadingExam) {
      Period period = leadingExam.getPeriod();
      for (FollowingExam followingExam : leadingExam.getFollowingExamList()) {
          scoreDirector.beforeVariableChanged(followingExam, "period");
          followingExam.setPeriod(period);
          scoreDirector.afterVariableChanged(followingExam, "period");
  
          //additional lines of code to update the "var" variable
          Integer var = followingExam.getVar();
          if(var == null){
              var = new Integer(1);
          }
          else var++;
          scoreDirector.beforeVariableChanged(followingExam, "var");
          followingExam.setVar(var);
          scoreDirector.afterVariableChanged(followingExam, "var");
  
      }
  }
  
  }
  </code></pre>
  
  <p>It also seem like that there is no problem for OptaPlanner registering that this is another shadow variable because i get this message when i run the application</p>
  
  <pre><code>2016-04-11 15:26:15,309 [AWT-EventQueue-0] TRACE     Model annotations parsed for Solution Examination:
  2016-04-11 15:26:15,309 [AWT-EventQueue-0] TRACE         Entity Exam:
  2016-04-11 15:26:15,309 [AWT-EventQueue-0] TRACE             Variable room (genuine)
  2016-04-11 15:26:15,309 [AWT-EventQueue-0] TRACE         Entity LeadingExam:
  2016-04-11 15:26:15,309 [AWT-EventQueue-0] TRACE             Variable period (genuine)
  2016-04-11 15:26:15,309 [AWT-EventQueue-0] TRACE         Entity FollowingExam:
  2016-04-11 15:26:15,309 [AWT-EventQueue-0] TRACE             Variable period (shadow)
  2016-04-11 15:26:15,309 [AWT-EventQueue-0] TRACE             Variable var (shadow)
  </code></pre>
  
  <p>The error that i get is the next error , this error only appears when i change the environment mode to FULL_ASSERT ,but when it is left to the default REPRODUCIBLE it runs without any errors.</p>
  
  <pre><code>Caused by: java.lang.IllegalStateException: VariableListener corruption: the entity (426)'s shadow variable (FollowingExam.var)'s corrupted value (null) changed to uncorrupted value (1) after all VariableListeners were triggered without changes to the genuine variables.
  Probably the VariableListener class for that shadow variable (FollowingExam.var) forgot to update it when one of its sources changed after completedAction (Initial score calculated).
  at org.optaplanner.core.impl.score.director.AbstractScoreDirector.assertShadowVariablesAreNotStale(AbstractScoreDirector.java:349)
  at org.optaplanner.core.impl.solver.recaller.BestSolutionRecaller.solvingStarted(BestSolutionRecaller.java:84)
  at org.optaplanner.core.impl.solver.DefaultSolver.solvingStarted(DefaultSolver.java:196)
  at org.optaplanner.core.impl.solver.DefaultSolver.solve(DefaultSolver.java:175)
  at org.optaplanner.examples.common.business.SolutionBusiness.solve(SolutionBusiness.java:307)
  at org.optaplanner.examples.common.swingui.SolverAndPersistenceFrame$SolveWorker.doInBackground(SolverAndPersistenceFrame.java:287)
  at org.optaplanner.examples.common.swingui.SolverAndPersistenceFrame$SolveWorker.doInBackground(SolverAndPersistenceFrame.java:1)
  at javax.swing.SwingWorker$1.call(Unknown Source)
  at java.util.concurrent.FutureTask.run(Unknown Source)
  at javax.swing.SwingWorker.run(Unknown Source)
  at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
  at java.lang.Thread.run(Unknown Source)
  </code></pre>