eclipse / microprofile-metrics

microprofile-metrics
Apache License 2.0
100 stars 66 forks source link

Stop requiring nonNull values in MetadataBuilder for fields which are not required #464

Closed jmartisk closed 4 years ago

jmartisk commented 5 years ago

For example, calling metadataBuilder.description(null) throws an error even though description is not a required field. I don't see a reason for that. The undesired consequence is that if someone is building a new Metadata object and doesn't know in advance which fields will be null (the values passed from somewhere else), they have to introduce if conditions into the code, and thus can't properly use the fluent API of the builder.

pilhuhn commented 5 years ago

What if we don't change the existing api and introduce new methods for the optional parameters like .optionalDescription(@Nullable description)

jmartisk commented 5 years ago

Except I'm not sure about the @Nullable annotation, for that we would need to import some third party library, like the Checker framework or something. Or is there something standard bundled with the JDK? Just JDK internal stuff that isn't really meant to be used like this.