Uploaded image for project: 'Struts 2'
  1. Struts 2
  2. WW-2834

LocalizedTextUtil messageFormats cache is NOT thread safe

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Critical
    • Resolution: Fixed
    • 2.0.11.2
    • 2.1.3
    • Core Interceptors
    • None
    • Important

    Description

      Here is a snippet from com.opensymphony.xwork2.util.LocalizedTextUtil that illustrates one (could be more) problem. This could be easily fixed by using the JDK 1.5 ConcurrentHashMap collection instead. I guess technically this is an XWork problem but it is used by the default TextProvider implementation.

      private static final Map messageFormats = new HashMap();

      private static MessageFormat buildMessageFormat(String pattern, Locale locale) {
      MessageFormatKey key = new MessageFormatKey(pattern, locale);
      MessageFormat format = (MessageFormat) messageFormats.get(key);
      if (format == null)

      { format = new MessageFormat(pattern); format.setLocale(locale); format.applyPattern(pattern); messageFormats.put(key, format); }

      return format;
      }

      Also the MessageFormat class itself is not thread safe and must be syncronized.

      Attachments

        Activity

          People

            Unassigned Unassigned
            blackbeltdev Kirk Rasmussen
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: