diff --git a/logback-classic/src/main/java/ch/qos/logback/classic/util/LogbackMDCAdapter.java b/logback-classic/src/main/java/ch/qos/logback/classic/util/LogbackMDCAdapter.java index aa643cc136..78cef30950 100644 --- a/logback-classic/src/main/java/ch/qos/logback/classic/util/LogbackMDCAdapter.java +++ b/logback-classic/src/main/java/ch/qos/logback/classic/util/LogbackMDCAdapter.java @@ -18,7 +18,7 @@ import java.util.Collections; import java.util.Deque; -import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.Map; import java.util.Set; @@ -71,7 +71,7 @@ public void put(String key, String val) throws IllegalArgumentException { } Map current = readWriteThreadLocalMap.get(); if (current == null) { - current = new HashMap(); + current = new LinkedHashMap<>(); readWriteThreadLocalMap.set(current); } @@ -138,7 +138,7 @@ public Map getPropertyMap() { if (readOnlyMap == null) { Map current = readWriteThreadLocalMap.get(); if (current != null) { - final Map tempMap = new HashMap(current); + final Map tempMap = new LinkedHashMap<>(current); readOnlyMap = Collections.unmodifiableMap(tempMap); readOnlyThreadLocalMap.set(readOnlyMap); } @@ -155,7 +155,7 @@ public Map getCopyOfContextMap() { if (readOnlyMap == null) { return null; } else { - return new HashMap(readOnlyMap); + return new LinkedHashMap(readOnlyMap); } } @@ -176,7 +176,7 @@ public Set getKeys() { @SuppressWarnings("unchecked") public void setContextMap(Map contextMap) { if (contextMap != null) { - readWriteThreadLocalMap.set(new HashMap(contextMap)); + readWriteThreadLocalMap.set(new LinkedHashMap<>(contextMap)); } else { readWriteThreadLocalMap.set(null); }