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
No value ListProperty
and SetProperty
shouldn't allow adding elements
#7485
Comments
It seems really confusing to me that a List property starts out with "no value", just like I would never expect a List-returning method to return |
Just a though, not arguing against. If we consider every other properties, we allow them to have no value to force people to set a least a default value. With that regards, it does make sense to start out with no value. |
What about allowing build logic authors to say either "this is a property of type X and its initial value is Y", or, "this is a property of type X and please use the default value for this type as initial value" |
@eskatos The initial value can be set using |
Yep, agreed @lacasseio. I was suggesting to go a bit further and provide a way to say "use the default for this type as initial value". But I guess that explicit initial value with |
We also want to make clear the difference between "this is the initial value" and "this is the default". if the default is hard/expensive to calculate, we want to only use it when no other opinion has been given. |
Related to the issue that @big-guy and I spent 45 min debugging when I was changing the The The fix required adding a check to see if the gradle/subprojects/plugins/src/main/java/org/gradle/api/plugins/BasePlugin.java Lines 90 to 92 in d09ae3c
Would it be valuable on the Something like |
@lacasseio Do we have some discussion why collection properties should start out with no value? I would have expected that collection properties always have a value, the value being I don't see much value in distinguishing between the "not present" value and the "empty" value of a collection property. What is the use case for it? We also have a |
That is a great question. If I remember correctly, it started out when we removed the default values of the property of the primitive box type. @adammurdoch can give more feedback on this decision. |
This is also a breaking change in |
Any considerations for changing the behavior back before |
Please consider changing the behavior, or at least fixing this issue. Even though I knew about this issue and commented on it several times I still missed a few areas in our plugins that we released in support for 5.0 that break in surprising user-facing ways. Given a plugin that has an optional list property: @get:Input
@get:Optional
val things: ListProperty<String> = objectFactory.listProperty() A user can add to that list:
But the value is considered not present:
So, if a plugin implementation doesn't initialize the property to I can sort of understand the consistency across properties around having "no value", but the behavior today is surprising and seems needlessly complex. What benefits are there to having multi-valued properties like |
We'll try for a fix in 5.1, probably by just changing the default back to an empty collection and maybe some way for a plugin to create a collection property with no value if it really wants to. |
Default value is now an empty list/set/map: #7963 |
I'm reviving this thread because even after re-reading it several times, it's unclear what the expected behavior should be. I don't mind the default value being an empty list but I need to be able to distinguish between Right now I'm doing this:
Can we make See apollographql/apollo-kotlin#1987 for more context. |
Expected Behavior
Current Behavior
Context
See: #7472
Given that the collectors list gets cleared when a value is set, wouldn't it be better to fail upon add and addAll on a ListProperty with no value? We can check if the value is NO_VALUE_COLLECTOR to assert this mutation. I went as far as running the debugger and saw that both collectors (no value and the one I added) were present and still couldn't obviously found the issue.
Steps to Reproduce (for bugs)
Your Environment
The text was updated successfully, but these errors were encountered: