New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Static factory parameter ordering changed in 2.8.x with inherited parameters #1488
Comments
I was hoping we have such a change under a feature flag. But I cannot find such thing. I might need to look into how it was before and why it's changed (probably when we've discontinued some hacks for older compilers, this might have been a collateral). I hope we can return that older behavior under a feature flag. Will be looking into it, but no estimates :-( |
Is there any progress on adding an option to use the older behaviour? |
@elucash Is this something you would accept a PR for? |
Sorry for delayed response. Sure, if PR would have a feature/style flag and will be able to turn that older sorting, that would be great and will be merged. I can look into this too, probably, this or next weekend. It seems like not that hard, but definitely, not trivial. It would be really easy if just we can easily change the order in which supertypes are considered, but I'm a bit anxious if there's more to it |
We noticed a behavioral change in the generated static factory in 2.8.x, when inheriting fields from a parent class.
For example, with the following code:
In 2.7.4 and below, Immutables generates
and in 2.7.5 and above, it generates:
I think that the new behavior is better, and in a few cases in our codebase we'd explicitly changed the subclass to be something like the following in order to force the parameter order.
However, we have great concerns about the safety of this migration - if the parameters are all of the same type, then reordering parameters can lead to really dangerous bugs.
Do you have any suggestions for how to migrate to 2.8.x and higher? I'm thinking that some kind of flag that we can pass to Immutables to detect if all fields are the same type AND there is a parent class that provides some fields, then emit a warning unless some annotation is added to the class indicating that it was checked?
The text was updated successfully, but these errors were encountered: