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

Formatter returns unexpected strings if locale is null.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 9
    • 9
    • core-libs
    • b122
    • b125
    • Verified

      Build: 9 122
      Steps to reproduce:
      1. Construct a new formatter with a null locale
      2. Format a Calendar and then check the result.

      Actual result:
      date/time is formatted to unreadable string. such as \u940f\ufffd

      Expected result:
      the result should be date/time string, Tuesday or May, etc.

      Sample code:
      //construct a new formatter
      Formatter f = new Formatter(new StringBuilder(), (Locale)null);
      //create a new calendar
      Calendar c1 = new GregorianCalendar(new SimpleTimeZone(-8 * 60 * 60 * 1000, TimeZone.getAvailableIDs(-8 * 60 * 60 * 1000)[0]), Locale.US);
      //set the date/time for the calendar
      c1.set(1995, 4, 23, 19, 48, 34);
      //format the calendar
      f.format("%ta", c1);
      //Expected result should be Tue, now the result is \u940f\ufffd
      System.out.println(f.toString());

      Additional:
      This issue doesn't reproduce in JDK 8u76, formatter returns "Tue" as expected.

            naoto Naoto Sato
            yliu Johnny Liu (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: