Skip to content

Commit 373fbcb

Browse files
committed
Fix ConcurrentModificationException #6732
1 parent fa826fd commit 373fbcb

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

api/all/src/main/java/io/opentelemetry/api/internal/ConfigUtil.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@
55

66
package io.opentelemetry.api.internal;
77

8+
import java.util.AbstractMap;
9+
import java.util.HashSet;
810
import java.util.Locale;
911
import java.util.Map;
12+
import java.util.Set;
13+
import java.util.stream.Collectors;
1014
import javax.annotation.Nullable;
1115

1216
/**
@@ -33,10 +37,15 @@ private ConfigUtil() {}
3337
*/
3438
public static String getString(String key, String defaultValue) {
3539
String normalizedKey = normalizePropertyKey(key);
40+
Set<Map.Entry<String, String>> properties = new HashSet<>(System.getProperties().entrySet())
41+
.stream().filter(entry -> entry.getKey() instanceof String && entry.getValue() instanceof String)
42+
.map(entry -> new AbstractMap.SimpleEntry<>((String) entry.getKey(), (String) entry.getValue()))
43+
.collect(Collectors.<Map.Entry<String, String>>toSet());
44+
3645
String systemProperty =
37-
System.getProperties().entrySet().stream()
38-
.filter(entry -> normalizedKey.equals(normalizePropertyKey(entry.getKey().toString())))
39-
.map(entry -> entry.getValue().toString())
46+
properties.stream()
47+
.filter(entry -> normalizedKey.equals(normalizePropertyKey(entry.getKey())))
48+
.map(Map.Entry::getValue)
4049
.findFirst()
4150
.orElse(null);
4251
if (systemProperty != null) {

0 commit comments

Comments
 (0)