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

SimpleDateFormat normalizing the date when an invalid date is passed.

    Details

    • Subcomponent:
    • CPU:
      x86_64
    • OS:
      windows_10

      Description

      ADDITIONAL SYSTEM INFORMATION :
      64-bit Operating System
      Windows 10
      Java(TM) SE Runtime Environment (build 1.8.0_191-b12)
      Java HotSpot(TM) 64-Bit Server VM (build 25.191-b12, mixed mode)

      A DESCRIPTION OF THE PROBLEM :
      SimpleDateFormat normalizing the date to next next month date when we input as invalid date.

      REGRESSION : Last worked in version 8u192

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      import java.text.ParseException;
      import java.text.SimpleDateFormat;
      import java.util.Date;

      public class DateTest {

          public static void main(final String[] args) {
              SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd");
              dateFormatter.setLenient(true);
              Date parse = null;
              try {
                  parse = dateFormatter.parse("2018-06-31");
              } catch (ParseException e) {
                  System.out.println("Parsing exception :" + e.getMessage());
              }
              System.out.println(parse);
          }
      }

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Expecting parsing exception since it is invalid date. In july 31st date doesn't exist
      ACTUAL -
      Sun Jul 01 00:00:00 IST 2018

      CUSTOMER SUBMITTED WORKAROUND :
      Using LocalDate for conversion
      DateTimeFormatter f = DateTimeFormatter.ISO_LOCAL_DATE;
      LocalDate ld = LocalDate.parse("2018-06-31", f);
      Caused by: java.time.DateTimeException: Invalid date 'JUNE 31'

      FREQUENCY : always


        Attachments

          Activity

            People

            • Assignee:
              psonal Pallavi Sonal
              Reporter:
              webbuggrp Webbug Group
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: