Skip to content

disallow adding a map to itself#474

Merged
boulter merged 1 commit into
masterfrom
disallow-adding-a-map-to-itself
Aug 14, 2020
Merged

disallow adding a map to itself#474
boulter merged 1 commit into
masterfrom
disallow-adding-a-map-to-itself

Conversation

@boulter

@boulter boulter commented Aug 14, 2020

Copy link
Copy Markdown
Contributor

Since serializing a map with references to itself is disasterous, let's try to prevent that when adding things to the map.

@Override
public void putAll(Map<? extends K, ? extends V> m) {
public void putAll(@Nonnull Map<? extends K, ? extends V> m) {
for (Entry<? extends K, ? extends V> entry : m.entrySet()) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you are iterating the entries, can you just call put(key, value) for each of the entry, and skip the scope.putAll(m)?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The HashMap implementation of putAll has some optimizations for inserting multiple entries, so I didn't want to override that.

@boulter boulter merged commit 06e6c27 into master Aug 14, 2020
@boulter boulter deleted the disallow-adding-a-map-to-itself branch August 14, 2020 17:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants