Use computeIfAbsent in ResourceBundleMessageSource
Closes gh-25072
This commit is contained in:
parent
30263137c4
commit
d60c55c296
|
@ -71,6 +71,7 @@ import org.springframework.util.ClassUtils;
|
||||||
*
|
*
|
||||||
* @author Rod Johnson
|
* @author Rod Johnson
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
|
* @author Qimiao Chen
|
||||||
* @see #setBasenames
|
* @see #setBasenames
|
||||||
* @see ReloadableResourceBundleMessageSource
|
* @see ReloadableResourceBundleMessageSource
|
||||||
* @see java.util.ResourceBundle
|
* @see java.util.ResourceBundle
|
||||||
|
@ -331,19 +332,10 @@ public class ResourceBundleMessageSource extends AbstractResourceBasedMessageSou
|
||||||
String msg = getStringOrNull(bundle, code);
|
String msg = getStringOrNull(bundle, code);
|
||||||
if (msg != null) {
|
if (msg != null) {
|
||||||
if (codeMap == null) {
|
if (codeMap == null) {
|
||||||
codeMap = new ConcurrentHashMap<>();
|
codeMap = this.cachedBundleMessageFormats.computeIfAbsent(bundle, b -> new ConcurrentHashMap<>());
|
||||||
Map<String, Map<Locale, MessageFormat>> existing =
|
|
||||||
this.cachedBundleMessageFormats.putIfAbsent(bundle, codeMap);
|
|
||||||
if (existing != null) {
|
|
||||||
codeMap = existing;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (localeMap == null) {
|
if (localeMap == null) {
|
||||||
localeMap = new ConcurrentHashMap<>();
|
localeMap = codeMap.computeIfAbsent(code, c -> new ConcurrentHashMap<>());
|
||||||
Map<Locale, MessageFormat> existing = codeMap.putIfAbsent(code, localeMap);
|
|
||||||
if (existing != null) {
|
|
||||||
localeMap = existing;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
MessageFormat result = createMessageFormat(msg, locale);
|
MessageFormat result = createMessageFormat(msg, locale);
|
||||||
localeMap.put(locale, result);
|
localeMap.put(locale, result);
|
||||||
|
|
Loading…
Reference in New Issue