coherence-community / oracle-bedrock

Oracle Bedrock
Other
55 stars 31 forks source link

OptionsByType.getOrDefault should not cause side-effects #351

Closed brianoliver closed 8 years ago

brianoliver commented 8 years ago

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.