Skip to content

Commit d736406

Browse files
committed
Cloning properties in order to safely iterate over them
1 parent 329c05d commit d736406

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import java.util.Locale;
99
import java.util.Map;
1010
import java.util.Objects;
11+
import java.util.Properties;
1112
import javax.annotation.Nullable;
1213

1314
/**
@@ -35,13 +36,16 @@ private ConfigUtil() {}
3536
public static String getString(String key, String defaultValue) {
3637
String normalizedKey = normalizePropertyKey(key);
3738

39+
// Cloning in order to avoid ConcurrentModificationException
40+
// see https://github.com/open-telemetry/opentelemetry-java/issues/6732
3841
String systemProperty =
39-
System.getProperties().stringPropertyNames().stream()
40-
.filter(propertyName -> normalizedKey.equals(normalizePropertyKey(propertyName)))
41-
.map(System::getProperty)
42-
.filter(Objects::nonNull)
43-
.findFirst()
44-
.orElse(null);
42+
((Properties) System.getProperties().clone())
43+
.stringPropertyNames().stream()
44+
.filter(propertyName -> normalizedKey.equals(normalizePropertyKey(propertyName)))
45+
.map(System::getProperty)
46+
.filter(Objects::nonNull)
47+
.findFirst()
48+
.orElse(null);
4549
if (systemProperty != null) {
4650
return systemProperty;
4751
}

0 commit comments

Comments
 (0)