CDI @ConfigProperty primitive types should default to 0/false #476
Labels
area: CDI
Issue related to the CDI area
impl. proposal ⚙️
An issue or PR which proposes an implementation of use case(s) (link use case(s) in comments)
incompatible change ⚠️
A change that introduces an incompatibility compared to previous releases; major versions only
Milestone
If a CDI
@ConfigProperty
is defined with a primitive type, and no default value is given for the property, it may be substantially less surprising to default the property to 0 orfalse
(depending on the type of course) than it would be to make the property be required by default. If the property is required by default, the evidence suggests that most people will manually give a default value of 0 orfalse
to match their intuitive understanding of how Java primitive fields are initialized.It should still be possible to create a default value of
""
for such properties, which would cause specification of the property in configuration to be mandatory.It is worth discussing whether this behavior makes sense to extend to the corresponding primitive wrapper types as well. If a primitive wrapper type is desired, but the value is meant to be optional, then
OptionalInt
/OptionalLong
/OptionalDouble
/Optional<WrapperType>
should normally be used instead, to prevent users from having to deal withnull
.Note that this does not extend to properties of type
char
, for which a default value of'\0'
might be confusing.The final conclusion to the discussion should be codified in the specification.
The text was updated successfully, but these errors were encountered: