Uploaded image for project: 'OptaPlanner'
  1. OptaPlanner
  2. PLANNER-718

NPE in AbstractScoreDirector on CustomShadowVariable with variableListenerRef

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Minor Minor
    • 7.0.0.Beta7
    • 7.0.0.Beta2
    • optaplanner-core
    • None
    • NEW
    • NEW

      When using a custom shadow variable with a reference to another custom shadow variable like in the example below:

          @PlanningVariable(valueRangeProviderRefs = {"routeRange", "itemRange"},
                  graphType = CHAINED)
          public RoutePunt getPreviousRoutePunt() {
              return previousRoutePunt;
          }
      
          @CustomShadowVariable(variableListenerClass = ItemTimeUpdatingVariableListener.class, sources = {
                  @PlanningVariableReference(variableName = "previousRoutePunt"),
                  @PlanningVariableReference(variableName = "route"),
                  @PlanningVariableReference(variableName = "nextItem")})
          public Duration getActualDuration() {
              return actualDuration;
          }
      
          @CustomShadowVariable(variableListenerRef = @PlanningVariableReference(variableName = "actualDuration"))
          public LocalDateTime getPlannedArrivalTime() {
              return plannedArrivalTime;
          }
      

      When a corruption occurs in the plannedArrivalTime (example above) the following NPE appears.

      Exception in thread "1" java.lang.NullPointerException
      	at org.optaplanner.core.impl.score.director.AbstractScoreDirector.assertShadowVariablesAreNotStale(AbstractScoreDirector.java:415)
      	at org.optaplanner.core.impl.solver.recaller.BestSolutionRecaller.solvingStarted(BestSolutionRecaller.java:83)
      	at org.optaplanner.core.impl.solver.DefaultSolver.solvingStarted(DefaultSolver.java:218)
      	at org.optaplanner.core.impl.solver.DefaultSolver.solve(DefaultSolver.java:197)
      	at x.x.x.x.x.lambda$null$1(x.java:48)
      	at java.lang.Thread.run(Thread.java:745)
      

      This is caused by the VariableListenerClass which is null on referenced shadow variable

              gdesmet@redhat.com Geoffrey De Smet (Inactive)
              sjoerdkok Sjoerd Kok (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:
                Resolved: