This changes the display name from null to the value of name which should be unintended and unexpected.
This is especially problematic as by specification the Metadata has to be identical when doing a get or create lookup - otherwise the lookup is an illegal attempt to create the same metric with differing Metadata. (This is not the case as equals uses getDisplayName() which is the name in both cases`)
The problematic line is in constructor of MetadataBuilder
this.displayName = metadata.getDisplayName();
which for DefaultMetadata is implemented as:
Optional.ofNullable(displayName).orElse(name);
Suggested change is to use same pattern for display name as used for unit and description or to simply do a actual copy of the field reference for display name.
If display name should be initialised to name as default this could be done in connection with withName on the builder in case the display name is not set or empty. But considering that getDisplayName() does already return the name field in case displayName is null there is no need to set a default for displayName field.
When creating a
Metadata
object with display name intentionally set to not present as inand such a
Metadata
object is then modified usingThis changes the display name from
null
to the value ofname
which should be unintended and unexpected.This is especially problematic as by specification the(This is not the case asMetadata
has to be identical when doing a get or create lookup - otherwise the lookup is an illegal attempt to create the same metric with differingMetadata
.equals
usesgetDisplayName()
which is the name in both cases`)The problematic line is in constructor of
MetadataBuilder
which for
DefaultMetadata
is implemented as:Suggested change is to use same pattern for display name as used for unit and description or to simply do a actual copy of the field reference for display name.
If display name should be initialised to name as default this could be done in connection with
withName
on the builder in case the display name is not set or empty. But considering thatgetDisplayName()
does already return thename
field in casedisplayName
is null there is no need to set a default fordisplayName
field.