Skip to content

Commit 2709f77

Browse files
committed
Collect to named contributors to LinkedHashMap
Update `NamedContributorsMapAdapter` to collect items to a `LinkedHashMap` rather than a `HashMap`. See gh-31676
1 parent a4bafa8 commit 2709f77

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/NamedContributorsMapAdapter.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818

1919
import java.util.Collections;
2020
import java.util.Iterator;
21+
import java.util.LinkedHashMap;
2122
import java.util.Map;
2223
import java.util.Map.Entry;
2324
import java.util.function.Function;
24-
import java.util.stream.Collectors;
2525

2626
import org.springframework.util.Assert;
2727

@@ -43,8 +43,9 @@ abstract class NamedContributorsMapAdapter<V, C> implements NamedContributors<C>
4343
Assert.notNull(map, "Map must not be null");
4444
Assert.notNull(valueAdapter, "ValueAdapter must not be null");
4545
map.keySet().forEach(this::validateKey);
46-
this.map = Collections.unmodifiableMap(map.entrySet().stream()
47-
.collect(Collectors.toMap(Entry::getKey, (entry) -> adapt(entry.getValue(), valueAdapter))));
46+
this.map = Collections.unmodifiableMap(map.entrySet().stream().collect(LinkedHashMap::new,
47+
(result, entry) -> result.put(entry.getKey(), adapt(entry.getValue(), valueAdapter)), Map::putAll));
48+
4849
}
4950

5051
private void validateKey(String value) {

0 commit comments

Comments
 (0)