-
Notifications
You must be signed in to change notification settings - Fork 164
Description
In the near future, Java will start restricting deep reflection - for example, setAccessible(true) will become a problem.
To prepare for this future, the solver needs to do two things.
Require field access via getters/setters
If a class field being accessed (variable, shadow variable, fact/entity collection etc.) is not public, the solver has to access it via a getter and setter.
The field can still be annotated; read-only reflection should still be OK. But regardless of what is annotated, the access needs to happen through the getter/setter.
As this is a backwards incompatible behavior, we can only make this change in the next major version of the solver.
Redesign cloners
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.
PlanningClonableinterface; 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.