-
Notifications
You must be signed in to change notification settings - Fork 4.6k
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
Default value provided by ObjectFactory.property is inconsistent with Property.getOrElse behavior #6108
Comments
Thanks @grv87 for the great issue. It seems this behavior was explicitly defined code in the factory. The Javadoc specify the following: Boxed primitive types have the default value of the primitive type as defined by the JLS. I agree it's surprising in the sense that a developer would expect @adammurdoch What do you think should we do on this? I feel we could remove the default value in the factory method and add either an API to define the default value |
I'd be tempted to remove the default value from the factory method. Let's see if we need a convenience for setting an initial value at creation time (vs. just calling |
Maybe |
It could indeed. This would be a breaking change, however, because the signature baked into bytecode will be different. Which might be ok given that this API is incubating. I'm tempted perhaps to add a new method to replace |
Fix via #6695 |
#6780 does the same for collection properties. It also adds a |
Expected Behavior
Consider
Property
instance of Java standard type (e.g.Integer
) constructed byObjectFactory.property
. Supposeset
was never called. ThengetOrElse(someValue)
should returnsomeValue
.Current Behavior
getOrElse(someValue)
returns default value for that type defined by Java specification.Context
This also affects detection whether required property was set.
In the case of
getOrElse
, for optional properties, each time we have to reset property to null manually.In the case of required property, if developer would like to provide default value he should better set it explicitly.
Steps to Reproduce (for bugs)
getOrElse
on non-set property:gradle printNumber
prints0
instead of42
.gradle printString2
fails without its property set, butgradle printNumber2
succeedes.Your Environment
Gradle 4.9
The text was updated successfully, but these errors were encountered: