code: protected String formatMessage(String msg, Object[] args, Locale locale) {
          if (msg == null || (!this.alwaysUseMessageFormat && (args == null || args.length == 0))) {
              return msg;
          }
          MessageFormat messageFormat = null;
          synchronized (this.messageFormatsPerMessage) {
              Map<Locale, MessageFormat> messageFormatsPerLocale = this.messageFormatsPerMessage.get(msg);
              if (messageFormatsPerLocale != null) {
                  messageFormat = messageFormatsPerLocale.get(locale);
              } else {
                  messageFormatsPerLocale = new HashMap<>();
                  this.messageFormatsPerMessage.put(msg, messageFormatsPerLocale);
              }
              if (messageFormat == null) {
                  try {
                      messageFormat = createMessageFormat(msg, locale);
                  } catch (IllegalArgumentException ex) {
                      // invalid message format - probably not intended for formatting,
                      // rather using a message structure with no arguments involved
                      if (this.alwaysUseMessageFormat) {
                          throw ex;
                      }
                      // silently proceed with raw message if format not enforced
                      messageFormat = INVALID_MESSAGE_FORMAT;
                  }
                  messageFormatsPerLocale.put(locale, messageFormat);
              }
          }
          if (messageFormat == INVALID_MESSAGE_FORMAT) {
              return msg;
          }
          synchronized (messageFormat) {
              return messageFormat.format(args);
          }
      }
docs: Format the given message String, using cached MessageFormats.
  By default invoked for passed-in default messages, to resolve
  any argument placeholders found in them.
  
  @param msg the message to format
  @param args array of arguments that will be filled in for params within the message, or {@code null} if none
  @param locale the Locale used for formatting
  @return the formatted message (with resolved arguments)