Uploaded image for project: 'Commons Text'
  1. Commons Text
  2. TEXT-106

Exception thrown in ExtendedMessageFormat using quotes with custom registry

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.1
    • 1.2
    • None

    Description

      An exception is thrown when a quote is used just before end brace of format element definition when a custom registry is used.

      This exception is not thrown when a blank space is added before the end brace.

      public static void main(String[] args)
      {
      	String pattern           = "TEST: {0,choice,0#0|0<'1'}";
      	String patternWorkaround = "TEST: {0,choice,0#0|0<'1' }"; // a space after quote
      
      	// Works fine
      	MessageFormat format0 = new MessageFormat(pattern);
      
      	System.out.println(format0.format(new Integer[] { 0 })); // "TEST: 0"
      	System.out.println(format0.format(new Integer[] { 1 })); // "TEST: 1"
      
      	// Works fine
      	ExtendedMessageFormat format1 = new ExtendedMessageFormat(pattern);
      
      	System.out.println(format1.format(new Integer[] { 0 })); // "TEST: 0"
      	System.out.println(format1.format(new Integer[] { 1 })); // "TEST: 1"
      
      	// Works fine
      	ExtendedMessageFormat format2 = new ExtendedMessageFormat(patternWorkaround, new HashMap<String, FormatFactory>());
      
      	System.out.println(format2.format(new Integer[] { 0 })); // "TEST: 0"
      	System.out.println(format2.format(new Integer[] { 1 })); // "TEST: 1 "
      
      	// Doesn't work
      	ExtendedMessageFormat format3 = new ExtendedMessageFormat(pattern, new HashMap<String, FormatFactory>());
      
      	System.out.println(format3.format(new Integer[] { 0 })); // Exception in thread "main" java.lang.IllegalArgumentException: Unterminated format element at position 9
      	System.out.println(format3.format(new Integer[] { 1 }));
      }
      

      Expected behavior: This exception should not be thrown.

      Attachments

        1. ExtendedMessageFormat.java.patch
          1 kB
          Benoît Moreau
        2. ExtendedMessageFormatTest.java.patch
          1 kB
          Benoît Moreau

        Issue Links

          Activity

            People

              kinow Bruno P. Kinoshita
              ben12 Benoît Moreau
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: