Closed as not planned
Closed as not planned
Description
If you use org.springframework.context.MessageSource#getMessage(java.lang.String, java.lang.Object[], java.lang.String, java.util.Locale)
and locale is null. When the org.springframework.context.support.MessageSourceSupport#formatMessage
method is executed, the ConcurrentHashMap
is used as the cache and the locale is null. As a result, the null pointer is generated when use null
as the key.
protected String formatMessage(String msg, @Nullable Object[] args, Locale locale) {
if (!isAlwaysUseMessageFormat() && ObjectUtils.isEmpty(args)) {
return msg;
}
Map<Locale, MessageFormat> messageFormatsPerLocale = this.messageFormatsPerMessage
.computeIfAbsent(msg, key -> new ConcurrentHashMap<>());
// NullPointerException thrown when locale is null
MessageFormat messageFormat = messageFormatsPerLocale.computeIfAbsent(locale, key -> {
try {
return createMessageFormat(msg, locale);
}
catch (IllegalArgumentException ex) {
// Invalid message format - probably not intended for formatting,
// rather using a message structure with no arguments involved...
if (isAlwaysUseMessageFormat()) {
throw ex;
}
// Silently proceed with raw message if format not enforced...
return INVALID_MESSAGE_FORMAT;
}
});
if (messageFormat == INVALID_MESSAGE_FORMAT) {
return msg;
}
synchronized (messageFormat) {
return messageFormat.format(resolveArguments(args, locale));
}
}