When using OptionsByType.getOrDefault, if the default value is not found, it is added to the OptionsByType collection and then returned. This side-effect can have unintended effects on OptionsByType collections, as simply testing for an Option can cause an option to be added.
Instead, OptionsByType.getOrDefault should simply return the default when not found and not mutate the collection. To support mutation we should add OptionsByType.getOrSetDefault.
As part of this fix we need to review existing internal uses of the getOrDefault method and where necessary, in extremely rare occurrences, replace with getOrSetDefault.
When using OptionsByType.getOrDefault, if the default value is not found, it is added to the OptionsByType collection and then returned. This side-effect can have unintended effects on OptionsByType collections, as simply testing for an Option can cause an option to be added.
Instead, OptionsByType.getOrDefault should simply return the default when not found and not mutate the collection. To support mutation we should add OptionsByType.getOrSetDefault.
As part of this fix we need to review existing internal uses of the getOrDefault method and where necessary, in extremely rare occurrences, replace with getOrSetDefault.