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

SimpleDateFormat ("MM/dd/yyyy") accepts "05/21/2a00e" but not "05/2a/2004"

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P3 P3
    • None
    • 1.4.2
    • core-libs
    • x86
    • windows_xp

      Name: js151677 Date: 06/01/2004


      FULL PRODUCT VERSION :
      J2SE 1.4.2_04 (on XP)
      or
      J2SE 1.3.1_02-b02 (on W2K)

      ADDITIONAL OS VERSION INFORMATION :
      Windows XP SP1
      Windows 2000 SP 3

      A DESCRIPTION OF THE PROBLEM :
      The parse method of class SimpleDateFormat accepts inputs like "05/21/20!�$%asdf" even if lenient is set to false. The resulting year is then 20 AD. On the other hand an input like "05/2a/2004" leads to a ParseException - what I would expect in both cases.

      Constructing the format with new java.text.SimpleDateFormat("MM/dd/yyyy"); leads to the same results, behaviour with using a German locale too.
       

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      compile and run the asttached test code

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      FAILED: java.text.ParseException: Unparseable date: "05/21/2a00e"

      ACTUAL -
      dateString 05/21/2a00e is formatted to Sun May 21 00:00:00 CEST 0002

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.text.*;
      import java.util.Locale;

      public class TestDFParser4WrongYear {
          
          public static void main(String [] args) {
              try {
                  SimpleDateFormat format = (SimpleDateFormat)DateFormat.getDateInstance(DateFormat.SHORT, Locale.US);
                  String dateString = "05/21/2a00e";
                  format.setLenient(false);
                  java.util.Date date = format.parse(dateString);
                  System.out.println("dateString " + dateString + " is formatted to " + date.toString());
              } catch (Exception ex) {
                  System.out.println("FAILED: " + ex.toString());
              }
          }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Parsing for character input if an era designator should not be provided.
      (Incident Review ID: 275821)
      ======================================================================

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

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: