From 2709f77ab99dd83729a6487e26cb3d989629f94c Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Wed, 27 Jul 2022 18:24:57 +0100 Subject: [PATCH] Collect to named contributors to `LinkedHashMap` Update `NamedContributorsMapAdapter` to collect items to a `LinkedHashMap` rather than a `HashMap`. See gh-31676 --- .../boot/actuate/health/NamedContributorsMapAdapter.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/NamedContributorsMapAdapter.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/NamedContributorsMapAdapter.java index 10040b8f0145..ccfb14c8a83f 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/NamedContributorsMapAdapter.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/NamedContributorsMapAdapter.java @@ -18,10 +18,10 @@ import java.util.Collections; import java.util.Iterator; +import java.util.LinkedHashMap; import java.util.Map; import java.util.Map.Entry; import java.util.function.Function; -import java.util.stream.Collectors; import org.springframework.util.Assert; @@ -43,8 +43,9 @@ abstract class NamedContributorsMapAdapter implements NamedContributors Assert.notNull(map, "Map must not be null"); Assert.notNull(valueAdapter, "ValueAdapter must not be null"); map.keySet().forEach(this::validateKey); - this.map = Collections.unmodifiableMap(map.entrySet().stream() - .collect(Collectors.toMap(Entry::getKey, (entry) -> adapt(entry.getValue(), valueAdapter)))); + this.map = Collections.unmodifiableMap(map.entrySet().stream().collect(LinkedHashMap::new, + (result, entry) -> result.put(entry.getKey(), adapt(entry.getValue(), valueAdapter)), Map::putAll)); + } private void validateKey(String value) {