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

Calendar.getTime throws excepting for Asia/Ho_Chi_Min timezone

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • None
    • core-libs
    • None

      Reproducible with Asia/Ho_Chi_Min timezone only.
      Here's a reproducer.

      import java.text.*;
      import java.util.*;
      import java.io.*;
      public class Ho {
          public static void main(String [] args) {
              testBrokenDate("Asia/Ho_Chi_Minh");
          }
          private static void testBrokenDate(String tz) {
              testBrokenDate(tz, 1942, Calendar.DECEMBER, 31, 23);
              testBrokenDate(tz, 1945, Calendar.MARCH, 14, 23);
              testBrokenDate(tz, 1959, Calendar.DECEMBER, 31, 23);
          }
          private static void testBrokenDate(String tz, int year, int month, int day, int hour) {
              TimeZone brokenTimeZone = TimeZone.getTimeZone(tz);
              DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, new Locale("en"));
              df.setLenient(false);
              df.setTimeZone(brokenTimeZone);
              Calendar calendar = df.getCalendar();
              calendar.set(year, month, day, hour, 0);
              calendar.getTime();
          }
      }

      Running the test throws exception

      $java Ho
      Exception in thread "main" java.lang.IllegalArgumentException: YEAR: 1942 -> 1943
      at java.base/java.util.GregorianCalendar.computeTime(GregorianCalendar.java:2826)
      at java.base/java.util.Calendar.updateTime(Calendar.java:3426)
      at java.base/java.util.Calendar.getTimeInMillis(Calendar.java:1812)
      at java.base/java.util.Calendar.getTime(Calendar.java:1785)
      at Ho.testBrokenDate(Ho.java:20)
      at Ho.testBrokenDate(Ho.java:9)
      at Ho.main(Ho.java:6)


      This seems to be caused by the timezone data for Asia/Ho_Chi_Min

      Zone Asia/Ho_Chi_Minh 7:06:40 - LMT 1906 Jul 1
                                                7:06:30 - PLMT 1911 May 1 # Phù Liá»…n MT
                                                7:00 - +07 1942 Dec 31 23:00
                                                8:00 - +08 1945 Mar 14 23:00
                                                9:00 - +09 1945 Sep 2
                                                7:00 - +07 1947 Apr 1
                                                8:00 - +08 1955 Jul 1
                                                7:00 - +07 1959 Dec 31 23:00
                                                8:00 - +08 1975 Jun 13
                                                7:00 - +07

            naoto Naoto Sato
            dcherepanov Dmitry Cherepanov
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: