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
Allow Provider#toString() to be consider as an error #16948
Comments
This issue has been automatically marked as stale because it has not had recent activity. Given the limited bandwidth of the team, it will be automatically closed if no further activity occurs. If you're interested in how we try to keep the backlog in a healthy state, please read our blog post on how we refine our backlog. If you feel this is something you could contribute, please have a look at our Contributor Guide. Thank you for your contribution. |
Please don't close this! This would be a major usability improvement for |
In the context of deprecating which is very different although making a lot of sense when you get your head around it. (yes the As part of that work, I was tripped a couple times initially by this I wonder if having Anyway, sharing this as one more element for the resolution of that issue. |
Just a quick thought: we could deprecate the |
In almost all use cases, calling
Provider#toString()
is the wrong intention. When migrating builds to use the provider API, there are a lot of cases where build authors would build strings out of property that now becomes providers. For example, in Groovy, code could look like this:propA = "${buildDir}/${propB}"
wherepropA
andpropB
are converted into Provider(s)/Property(s). We can think of other real use cases where the execution flow would implicitly and naturally callObject#toString()
. The problem here is the implicit call toProvider#toString()
is almost certainly a bug if not properly accounted for. Taking the previous example, the real intention would be something like the following:propA = propB.map { "${buildDir}/${it}" }
.It is understandable that
Provider#toString()
cannot rightfully throw an exception given theObject#toString()
contract. However, there should be a way that Gradle provides to ease the transition and catch those cases where the intent is wrong.Note: I'm well aware that some cases can be rewritten in different ways just like the example above but often it's unfeasible to rewrite or rethink all of the build logic. An incremental approach is much easier to implement, has a higher chance of success, easier to review, etc. The original code is most often good enough but lacks the capability to defer any execution to speed up configuration time.
Expected Behavior
Gradle can and should notify users when this particular case arises to avoid wrong intentions as well as making the transition easier. We can solve this in various ways, two of which are:
Provider#toString()
(cases, where the object type is only known at runtime, may not be possible to catch)Provider#toString()
contract and fail when called.Current Behavior
When adopting Gradle code to use the provider API, implicit calls to
Provider#toString()
are easily missed producing wrong results.Context
Anyone adopting the provider API will most certainly work through bugs caused by a similar scenario.
The text was updated successfully, but these errors were encountered: