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

Exception when combining custom and choice format in ExtendedMessageFormat

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.5, 2.6
    • 3.2
    • lang.text.*

    Description

      When using a custom format registered and a choice format with an inner format is used in the same message format, an IndexOutOfBoundsException occurs in the custructor of ExtendedMessageFormat:

      new ExtendedMessageFormat("Hi {0,test,any}, got {1,choice,0#none|1#one|1<{1,number}}", Collections.singletonMap("test", new TestFormatFactory()));
      java.lang.IndexOutOfBoundsException: Index: 2, Size: 2
      	at java.util.ArrayList.rangeCheck(ArrayList.java:604)
      	at java.util.ArrayList.get(ArrayList.java:382)
      	at org.apache.commons.lang.text.ExtendedMessageFormat.insertFormats(ExtendedMessageFormat.java:364)
      	at org.apache.commons.lang.text.ExtendedMessageFormat.applyPattern(ExtendedMessageFormat.java:192)
      	at org.apache.commons.lang.text.ExtendedMessageFormat.<init>(ExtendedMessageFormat.java:127)
      

      The problem occurs at the start of {1,number}.

      As a workaround i registered the TestFormatFactory also for "choice" and then returning new ChoiceFormat(arguments), but that is not the idea.

      I also checked the change logs, but there seems no change on this problem. I have not tester, but I think the bug still is present in the current release.

      Attachments

        1. LANG-917.patch
          2 kB
          Thomas Neidhart
        2. ExtendedMessageFormatTest.java
          2 kB
          Arne Burmeister

        Activity

          People

            Unassigned Unassigned
            aburmeis Arne Burmeister
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: