chore: Revert "fix: clone the solution before sending it to the consumer"#1648
Conversation
There was a problem hiding this comment.
Pull Request Overview
Revert the previous change that cloned the solution before sending it to consumers, restoring direct use of the solver’s internal instance and updating tests and docs accordingly.
- Removed the cloning-based test in BestSolutionHolderTest
- Updated assertions in DefaultConstructionHeuristicPhaseTest to expect the same instance
- Removed
cloneBestSolution()and related cloning calls in core solver classes; updated documentation to warn about in-place mutation
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| BestSolutionHolderTest.java | Removed test verifying cloning between phases |
| DefaultConstructionHeuristicPhaseTest.java | Changed assertion to check for same solution instance |
| SolverScope.java | Deleted cloneBestSolution() and inlined cloning call |
| SolverEventSupport.java | Stopped cloning before firing best-solution events |
| DefaultSolver.java | Returned internal best solution instead of a clone |
| SolverJobBuilder.java | Added docs warning consumers not to mutate the solution |
Comments suppressed due to low confidence (3)
core/src/main/java/ai/timefold/solver/core/impl/solver/event/SolverEventSupport.java:26
- [nitpick] Add a Javadoc comment on
fireBestSolutionChangedto warn that the solution is no longer cloned and consumers receive the live instance, so they should avoid mutating it.
var event = new DefaultBestSolutionChangedEvent<>(solver, timeMillisSpent, newBestSolution, bestScore);
core/src/main/java/ai/timefold/solver/core/impl/solver/DefaultSolver.java:207
- [nitpick] Update the method-level Javadoc for the solver’s
solve/runmethod to note that the returned solution is not cloned and is the internal solver instance.
return solverScope.getBestSolution();
core/src/test/java/ai/timefold/solver/core/impl/solver/BestSolutionHolderTest.java:187
- [nitpick] Introduce a new test that verifies mutations performed in
bestSolutionConsumerpersist into the final solution, ensuring this no-clone behavior is explicitly covered.
private record RecordedFuture(int id, CompletableFuture<Void> future) {
triceo
left a comment
There was a problem hiding this comment.
LGTM.
Ideally we'd mention this in the docs somewhere. Surely there is a section in there about SolutionManager and consuming the best solution. If not, perhaps it's a good time to add one.
9f68e93 to
a34426f
Compare
triceo
left a comment
There was a problem hiding this comment.
LGTM when docs improved.
|



No description provided.