Skip to content

Commit 3563546

Browse files
committed
copy entry set to avoid mutating original map
1 parent c192bd0 commit 3563546

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

src/main/java/com/bugsnag/util/FilteredMap.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import java.util.ArrayList;
55
import java.util.Collection;
6+
import java.util.HashSet;
67
import java.util.Map;
78
import java.util.Set;
89

@@ -85,12 +86,14 @@ public Collection<Object> values() {
8586
@Override
8687
public Set<Entry<String, Object>> entrySet() {
8788
Set<Entry<String, Object>> entries = map.entrySet();
89+
Set<Entry<String, Object>> copy = new HashSet<Entry<String, Object>>();
90+
copy.addAll(entries);
8891

89-
for (Entry<String, Object> entry : entries) {
92+
for (Entry<String, Object> entry : copy) {
9093
String key = entry.getKey();
9194
entry.setValue(transformEntry(key, entry.getValue()));
9295
}
93-
return entries;
96+
return copy;
9497
}
9598

9699
private Object transformEntry(Object key, Object value) {

0 commit comments

Comments
 (0)