Skip to content

Commit 5aa4fa6

Browse files
committed
fix: clone the solution before sending it to the consumer
1 parent f565b02 commit 5aa4fa6

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

core/src/main/java/ai/timefold/solver/core/impl/solver/recaller/BestSolutionRecaller.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,10 @@ public void updateBestSolutionAndFireIfInitialized(SolverScope<Solution_> solver
137137
private void updateBestSolutionAndFire(SolverScope<Solution_> solverScope, InnerScore<?> bestScore,
138138
Solution_ bestSolution) {
139139
updateBestSolutionWithoutFiring(solverScope, bestScore, bestSolution);
140-
// There is no need to clone the solution because the caller has already done that
141-
solverEventSupport.fireBestSolutionChanged(solverScope, solverScope.getBestSolution());
140+
// We need to clone the solution again, or we may use the same instance employed by the solver scope,
141+
// which is restored between solver phases.
142+
// The operation won't block the solving process.
143+
solverEventSupport.fireBestSolutionChanged(solverScope, solverScope.cloneBestSolution());
142144
}
143145

144146
@SuppressWarnings({ "unchecked", "rawtypes" })

0 commit comments

Comments
 (0)