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

Incompatibility SimpleDateFormat.applyLocalizedPattern between Sun JDK versions

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P2 P2
    • 5.0
    • 1.4.1
    • globalization
    • b45
    • generic
    • solaris_9

      According to the Javadoc, the applyLocalizedPattern method on
      SimpleDateFormat is supposed to take a localized date pattern and
      initialize the SimpleDateFormat object with that format. This will
      allow us to use that SimpleDateFormat object on a Date object to format
      a date string. However, it would appear that for JDK 1.4.x, this method
      no longer accepts localized pattern - i.e. in German, the localized
      pattern for a date would be "tt.MM.uuuu", where the non-localized
      pattern would be "dd.MM.yyyy". In 1.3.x, using that pattern works fine,
      but in 1.4.x, it no longer accepts that pattern.

      Reproduction Case:

      I have the following test program, test2.java:

      import java.text.*;
      import java.util.*;

      public class test2 {
        public static void main(String args[]) {
          try {
            SimpleDateFormat df = (SimpleDateFormat)
      DateFormat.getDateInstance(DateFormat.DEFAULT, Locale.GERMAN);
            df.applyLocalizedPattern("tt.MM.uuuu");
            System.out.println(df.format(new Date()));
          }
          catch (Exception e) {
            e.printStackTrace();
          }
        }
      }


      When I use JDK 1.3.1_04 to run this program, I get :
      10.02.2004

      When I use JDK 1.4.2_03 to run this program, I get:
      java.lang.IllegalArgumentException: Illegal pattern character 't'
      at
      java.text.SimpleDateFormat.translatePattern(SimpleDateFormat.java:1730)
      at
      java.text.SimpleDateFormat.applyLocalizedPattern(SimpleDateFormat.java:1
      785) at test2.main(test2.java:8)

            jtusla Jiri Tusla (Inactive)
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: