Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4086107

MessageFormat::parse doesn't parse last value if the pattern ends with its '}'

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      1.1.6
    • CPU:
      x86
    • OS:
      windows_nt
    • Verification:
      Verified

      Backports

        Description



        Name: bb33257 Date: 10/14/97


        MessageFormat::parse does not return the last value for patterns
        which end with a placeholder, like "{1},{2}" (end with '}').
        SOURCE CODE: The bug appears when the following test executes
        for the pattern: "There are {1} files on {2} at {3}"
        ---------------------------------------------------
          public void TestMSGPatternTest() throws Exception {// only here temporary, as a convenience for a first test
                Object[] testArgs = {
                    new Double (1), new Double(3456),
                    "Disk", new Date(10000000000)};

                String[] testCases = {
                   "Quotes '', '{', 'a' {0} '{0}'",
                   "Quotes '', '{', 'a' {0,number} '{0}'",
                   "'{'1,number,'#',##} {1,number,'#',##}",
                   "There are {1} files on {2} at {3}",
                   "On {2}, there are {1} files, with {0,number,currency}.",
                   "'{1,number,percent}', {1,number,percent}, ",
                   "'{1,date,full}', {1,date,full}, ",
                   "'{3,date,full}', {3,date,full}, ",
                   "'{1,number,#,##}' {1,number,#,##}",
                };

                for (int i = 0; i < testCases.length; ++i) {
                    try {
                        logln("");
                        logln( i + " Pat in: " + testCases[i]);
                        MessageFormat form = new MessageFormat(testCases[i]);
                        logln( i + " Pat out: " + form.toPattern());
                        String result = form.format(testArgs);
                        logln( i + " Result: " + result);
                        Object[] values = form.parse(result);
                        for (int j = 0; j < testArgs.length; ++j) {
                            if (testArgs[j] == null && values[j] != null
                                || testArgs[j] != null && !testArgs[j].equals(values[j])) {
                               logln( i + " " + j + " old: " + testArgs[j]);
                               logln( i + " " + j + " new: " + values[j]);
                            }
                        }
                 } catch (Exception foo) {
                 foo.printStackTrace();
                 }
                }

            }

        ======================================================================

          Attachments

            Issue Links

              Activity

                People

                Assignee:
                bcbeck Brian Beck (Inactive)
                Reporter:
                bcbeck Brian Beck (Inactive)
                Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                  Dates

                  Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: