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

REGRESSION: SimpleDateFormat.setLenient (false) behavior changed with jdk1.5.0

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P3 P3
    • None
    • 5.0
    • core-libs
    • x86
    • linux, windows_xp

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


      ADDITIONAL OS VERSION INFORMATION :
      Windows XP

      A DESCRIPTION OF THE PROBLEM :
      The following runs without output for jdk1.4.2 and jdk1.3.1. But for jdk1.5.0 it will print
      #1: java.text.ParseException: Unparseable date: "2002-08-01T14:00:00 GMT"

        To get the output showing the incompatible (and seems buggy) parse exception with jdk1.5.0
      just do
         javac Test.java
         java Test
      for the source below (as Test.java). Note if setLenient(false) is not done
      the exception output doesn't happen, e.g. if run "java Test xxx".

      Note also that if "GMT" below is extended as "GMT+05:00" or "GMT-05:00", then
          java Test
      will get the ParseException output line if jdk1.5.0 is used.

      // BEGIN Test.java
      import java.text.SimpleDateFormat;
      import java.text.ParseException;
      import java.util.TimeZone;
      import java.util.Locale;

      class Test {
      public static void main(String args[]) {
      Locale dl = Locale.ENGLISH;
      TimeZone dt = TimeZone.getTimeZone("PST");
      SimpleDateFormat f1 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss z", dl);
      f1.setTimeZone(dt);
      if (args.length == 0) {
      f1.setLenient(false);
      }

      try {
        f1.parse("2002-08-01T14:00:00 GMT");
      } catch (ParseException e) {
      System.err.println("#1: " + e);
      }

      }
      }
      // END

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      See the detailed descripton for the source and steps to reproduce. It's only 24 lines.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      I expect no println output when the program is run using jdk1.5.0 via
         java Test
      as output indicates an incompatiblity with earlier jdks (and seems wrong anyway).
      ACTUAL -
      When jdk1.5.0 java is used,
         java Test
      gives

      #1: java.text.ParseException: Unparseable date: "2002-08-01T14:00:00 GMT"

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.text.SimpleDateFormat;
      import java.text.ParseException;
      import java.util.TimeZone;
      import java.util.Locale;

      class Test {
      public static void main(String args[]) {
      Locale dl = Locale.ENGLISH;
      TimeZone dt = TimeZone.getTimeZone("PST");
      SimpleDateFormat f1 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss z", dl);
      f1.setTimeZone(dt);
      if (args.length == 0) {
      f1.setLenient(false);
      }

      try {
        f1.parse("2002-08-01T14:00:00 GMT"");
      } catch (ParseException e) {
      System.err.println("#1: " + e);
      }

      }
      }

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

      CUSTOMER SUBMITTED WORKAROUND :
      I suppose not setting lenient false may serve some folk as a workaround.,

      Release Regression From : 4.2
      The above release value was the last known release where this
      bug was known to work. Since then there has been a regression.
      ###@###.### 2005-03-30 12:40:21 GMT

            okutsu Masayoshi Okutsu
            jssunw Jitender S (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: