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

Date parsing exception with DateFormat.SHORT

    Details

      Description

      A DESCRIPTION OF THE PROBLEM :
      The following ant target, which attempts to delete files that are 3 days old (or older), throws an error under Java 9 and 10:

      <target name="-delete-old-log-files">
        <tstamp>
          <format property="old.file.stamp"
                  pattern="MM/dd/yyyy hh:mm a"
                  locale="en,UK"
                  offset="-3"
                  unit="day"/>
        </tstamp>
        <delete>
          <fileset dir="${logging.dir}" includes="*/**">
            <date datetime="${old.file.stamp}" when="before"/>
          </fileset>
        </delete>
      </target>

      Error thrown: "Date Cannot be parsed correctly. It should be in MM/DD/YYYY HH:MM AM_PM format"

      There are no issues when executing the same ant target under Java 8.

      REGRESSION : Last worked in version 8u172

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Build the Java program below with 1.8.0_172 and run under 1.8.0_172 and 10.0.1.




      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      long value
      ACTUAL -
      Exception in thread "main" java.text.ParseException: Unparseable date: "07/06/2018 10:56 AM"
      at java.base/java.text.DateFormat.parse(DateFormat.java:395)
      at Main.main(Main.java:10)

      ---------- BEGIN SOURCE ----------
      import java.text.DateFormat;
      import java.text.ParseException;
      import java.util.Locale;

      public class Main {

          public static void main(final String[] args) throws ParseException {

              final DateFormat df = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, Locale.US);
              final long millis = df.parse("07/06/2018 10:56 AM").getTime();
              System.out.println(millis);
          }
      }

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

      FREQUENCY : always


        Attachments

          Activity

            People

            • Assignee:
              nishjain Nishit Jain
              Reporter:
              webbuggrp Webbug Group
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: