TimefoldAI / TimefoldAI/timefold-solver

No longer rely on deep reflection in cloning

Open
#1,929 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
1.8k
Forks
228
Avg merge
1d 13h
Merged PRs (30d)
46

Description

In the near future, Java will start restricting deep reflection - for example, setAccessible(true) will become a problem.

The current approach to solution cloning relies heavily on deep reflection, and it can not be fixed. For example, the cloner will use setAccessible(true) to be able to write a final field after the encapsulating object was already created. A new approach to cloning will be necessary. Possibilities include:

  • @JsonCreator-like approach.
  • @ConstructorProperties-like approach.
  • PlanningClonable interface; maybe not ideal.
  • Wait until Java finishes serialization 2.0, which will likely provide mechanisms for this. Unfortunately, as this would require an upgrade of the minimum version of the JDK, this is unlikely to be applicable any time soon; a solution to this issue will likely be required earlier.
Gizmo cloner

We already support the Gizmo-based cloner, which does not use deep reflection. However, outside of Quarkus, it requires all mutable fields to be public, which arguably no user would be excited about doing. If we decide to go for the @JsonCreator approach, we may be able to fully generate cloners even without forcing the user to accept such workarounds, giving peak performance to everyone in all circumstances. As an added bonus, this would allow us to only have a single implementation of the cloner.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue does not name specific files or tests. Start by locating the current solution-cloning implementation and the Gizmo-based cloner, then compare how each handles mutable and final fields. Done means defining and implementing a replacement for deep reflection that works without requiring mutable fields to be public.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.