Uploaded image for project: 'Commons Lang'
  1. Commons Lang
  2. LANG-477

ExtendedMessageFormat: OutOfMemory with custom format registry and a pattern containing single quotes

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.4
    • 2.5
    • lang.text.*
    • None

    Description

      When using ExtendedMessageFormat with a custom format registry and a pattern conatining single quotes, an OutOfMemoryError will occur.

      Example that will cause error:

      ExtendedMessageFormatTest.java
      private static Map<String, Object> formatRegistry = new HashMap<String, Object>();    
          static {
              formatRegistry.put(DummyFormatFactory.DUMMY_FORMAT, new DummyFormatFactory());
          }
          
          public static void main(String[] args) {
              ExtendedMessageFormat mf = new ExtendedMessageFormat("it''s a {dummy} 'test'!", formatRegistry);
              String formattedPattern = mf.format(new String[] {"great"});
              System.out.println(formattedPattern);
          }
      }
      
      

      The following change starting at line 421 on the 2.4 release seems to fix the problem:

      ExtendedMessageFormat.java
      CURRENT (Broken):
      if (escapingOn && c[start] == QUOTE) {
              return appendTo == null ? null : appendTo.append(QUOTE);
      }
      
      WORKING:
      if (escapingOn && c[start] == QUOTE) {
              next(pos);
              return appendTo == null ? null : appendTo.append(QUOTE);
      }
      

      Attachments

        1. DummyFormat.java
          0.6 kB
          Duncan Eley
        2. DummyFormatFactory.java
          0.5 kB
          Duncan Eley
        3. ExtendedMessageFormatTest.java
          0.7 kB
          Duncan Eley

        Issue Links

          Activity

            People

              niallp Niall Pemberton
              djeley Duncan Eley
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: