From d64edc518968409da337ad65120a9c486570b854 Mon Sep 17 00:00:00 2001 From: tianshuang Date: Sat, 1 Oct 2022 21:00:54 +0800 Subject: [PATCH] Fix a race condition caused by other threads calling mapper methods while mappedStatements are being constructed --- .../org/apache/ibatis/session/Configuration.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/apache/ibatis/session/Configuration.java b/src/main/java/org/apache/ibatis/session/Configuration.java index 3c257379e8b..82f0f90b263 100644 --- a/src/main/java/org/apache/ibatis/session/Configuration.java +++ b/src/main/java/org/apache/ibatis/session/Configuration.java @@ -25,6 +25,7 @@ import java.util.Map; import java.util.Properties; import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; import java.util.function.BiFunction; import org.apache.ibatis.binding.MapperRegistry; @@ -998,7 +999,7 @@ protected void checkLocallyForDiscriminatedNestedResultMaps(ResultMap rm) { } } - protected static class StrictMap extends HashMap { + protected static class StrictMap extends ConcurrentHashMap { private static final long serialVersionUID = -4950446264854982944L; private final String name; @@ -1055,6 +1056,15 @@ public V put(String key, V value) { return super.put(key, value); } + @Override + public boolean containsKey(Object key) { + if (key == null) { + return false; + } + + return super.get(key) != null; + } + @Override public V get(Object key) { V value = super.get(key);