Skip to content

Commit

Permalink
Fix ConcurrentModificationException #6732
Browse files Browse the repository at this point in the history
  • Loading branch information
neugartf committed Sep 25, 2024
1 parent fa826fd commit 373fbcb
Showing 1 changed file with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@

package io.opentelemetry.api.internal;

import java.util.AbstractMap;
import java.util.HashSet;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import javax.annotation.Nullable;

/**
Expand All @@ -33,10 +37,15 @@ private ConfigUtil() {}
*/
public static String getString(String key, String defaultValue) {
String normalizedKey = normalizePropertyKey(key);
Set<Map.Entry<String, String>> properties = new HashSet<>(System.getProperties().entrySet())
.stream().filter(entry -> entry.getKey() instanceof String && entry.getValue() instanceof String)
.map(entry -> new AbstractMap.SimpleEntry<>((String) entry.getKey(), (String) entry.getValue()))
.collect(Collectors.<Map.Entry<String, String>>toSet());

String systemProperty =
System.getProperties().entrySet().stream()
.filter(entry -> normalizedKey.equals(normalizePropertyKey(entry.getKey().toString())))
.map(entry -> entry.getValue().toString())
properties.stream()
.filter(entry -> normalizedKey.equals(normalizePropertyKey(entry.getKey())))
.map(Map.Entry::getValue)
.findFirst()
.orElse(null);
if (systemProperty != null) {
Expand Down

0 comments on commit 373fbcb

Please sign in to comment.