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

REGRESSION in 1.3.1_11: SimpleDateFormat wrong parse behaviour

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P2 P2
    • None
    • 1.3.1_11
    • core-libs
    • x86
    • solaris_2.5.1

      Name: js151677 Date: 08/11/2004


      FULL PRODUCT VERSION :
      java version "1.3.1_10"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1_10-b03)
      Java HotSpot(TM) Client VM (build 1.3.1_10-b03, mixed mode)

      java version "1.3.1_12"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1_12-b03)
      Java HotSpot(TM) Client VM (build 1.3.1_12-b03, mixed mode)

      java version "1.4.2_05"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_05-b04)
      Java HotSpot(TM) Client VM (build 1.4.2_05-b04, mixed mode)


      ADDITIONAL OS VERSION INFORMATION :
      uname -a
      Linux caruncho 2.4.19-4GB #1 Mon Jun 28 15:57:57 UTC 2004 i686 unknown

      Distribution Sun Java Desktop R2
      Also tested under solaris, same results

      A DESCRIPTION OF THE PROBLEM :
      We are facing some parsing problems in j2se 1.3.1_11, j2se 1.3.1_12 that working in previous releases <= j2se 1.3.1_10 and in the new J2SE 1.4.2_05

      Parsing dates string with lenient off gives wrong results ( i think the dayligth savings are added to date)


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Just run the test case with jdk1.3.1_11 (or jdk1.3.1_12) to obtain a wrong output and with
      and <= jdk1.3.1_10 or 1.4.2_05 to obtain the expected result

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      I allways expected that parsing the same string with the same date format, give the same date in different versions of J2SE
      ACTUAL -
      Using jdk1.3.1_11 (Result NOT OK)
      Lenient is 1 parse 2004-08-10 20:12:15 DateTime=1092165135000 DateToString=Tue Aug 10 20:12:15 BST 2004
      Lenient is 0 parse 2004-08-10 20:12:15 DateTime=1092168735000 DateToString=Tue Aug 10 21:12:15 BST 2004

      Note that in the output "Lenient is 0 parse..." the sames date format was used to parse the same date, but with lenient off, and 1 hour was added to the date, with the same timezone (Europe/London)


      Using jdk1.3.1_10 (Result OK)
      Lenient is 1 parse 2004-08-10 20:12:15 DateTime=1092165135000 DateToString=Tue Aug 10 20:12:15 BST 2004
      Lenient is 0 parse 2004-08-10 20:12:15 DateTime=1092165135000 DateToString=Tue Aug 10 20:12:15 BST 2004

      Using jdk1.4.2_05 (Result OK)
      Lenient is 1 parse 2004-08-10 20:12:15 DateTime=1092165135000 DateToString=Tue Aug 10 20:12:15 BST 2004
      Lenient is 0 parse 2004-08-10 20:12:15 DateTime=1092165135000 DateToString=Tue Aug 10 20:12:15 BST 2004


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      public class LenientTest {

      public LenientTest() throws Exception {

      TimeZone.setDefault(TimeZone.getTimeZone("Europe/London"));

      final DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
      Date dt;

      df.setLenient(true);
      String time = "2004-08-10 20:12:15";
      dt = df.parse(time);
      outputDate(1, time, dt);
      df.setLenient(false);
      dt = df.parse(time);
      outputDate(0, time, dt);
      }

      private static final void outputDate(int lenient, String time, Date dt) {
      System.out.println("Lenient is " + lenient + " parse " + time + " DateTime=" + dt.getTime() + " DateToString=" + dt);
      }

      public static void main(String[] args) throws Exception {
      LenientTest untitled11 = new LenientTest();

      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Use <= j2se 1.3.1_10, or j2se 1.4 (tested only with j2se_1.4.2_05)
      (Incident Review ID: 296618)
      ======================================================================

            minqi Yumin Qi
            jssunw Jitender S (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: