Use computeIfAbsent in ResourceBundleMessageSource

Closes gh-25072
This commit is contained in:
陈其苗 2020-05-14 11:22:07 +08:00 committed by Sam Brannen
parent 30263137c4
commit d60c55c296
1 changed files with 3 additions and 11 deletions

View File

@ -71,6 +71,7 @@ import org.springframework.util.ClassUtils;
*
* @author Rod Johnson
* @author Juergen Hoeller
* @author Qimiao Chen
* @see #setBasenames
* @see ReloadableResourceBundleMessageSource
* @see java.util.ResourceBundle
@ -331,19 +332,10 @@ public class ResourceBundleMessageSource extends AbstractResourceBasedMessageSou
String msg = getStringOrNull(bundle, code);
if (msg != null) {
if (codeMap == null) {
codeMap = new ConcurrentHashMap<>();
Map<String, Map<Locale, MessageFormat>> existing =
this.cachedBundleMessageFormats.putIfAbsent(bundle, codeMap);
if (existing != null) {
codeMap = existing;
}
codeMap = this.cachedBundleMessageFormats.computeIfAbsent(bundle, b -> new ConcurrentHashMap<>());
}
if (localeMap == null) {
localeMap = new ConcurrentHashMap<>();
Map<Locale, MessageFormat> existing = codeMap.putIfAbsent(code, localeMap);
if (existing != null) {
localeMap = existing;
}
localeMap = codeMap.computeIfAbsent(code, c -> new ConcurrentHashMap<>());
}
MessageFormat result = createMessageFormat(msg, locale);
localeMap.put(locale, result);