the implementation of ListProperty
appears to make it very difficult to use as an optional value, i.e. getOrElse
will never produce the value specified as orElse
The reason being that a AbstractCollectionProperty
initialises the property with defaultValue = emptySupplier()
and convention = noValueSupplier()
emptySupplier
yields an empty list so has presence
in property terms which means that getOrElse
will always resolve to get
(as there is a value present for it to get)
The only workaround for this that I can find is to add a call like this
Iterable<String> empty = null
myListStringProperty.set(empty)
In groovy, this further requires use of @CompileStatic
to enable it to disambiguate between set(Iterable<String>)
and set(Provider)
This seems v clumsy behaviour at best (and it’s also not documented as far as I can see). Is there a better way to do this or is the implementation somewhat flawed?