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

java.time: DateTimeFormatter containing "DD" fails on 3-digit day-of-year value

    Details

    • Subcomponent:
    • Resolved In Build:
      b118
    • CPU:
      x86_64
    • OS:
      windows_7

      Description

      FULL PRODUCT VERSION :
      java version "1.8.0_40"
      Java(TM) SE Runtime Environment (build 1.8.0_40-b25)
      Java HotSpot(TM) 64-Bit Server VM (build 25.40-b25, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 6.1.7601]

      A DESCRIPTION OF THE PROBLEM :
      With the new java.time API, a DateTimeFormatter containing "DD" fails on a 3-digit day-of-year value.
      So for example, "123 2010" and "003 1980" fail to be parsed with: DateTimeFormatter.ofPattern("DD yyyy")

      On the other hand, "123 2010" and "003 1980" are parsed correctly with both:
      DateTimeFormatter.ofPattern("D yyyy")
      and
      DateTimeFormatter.ofPattern("DDD yyyy")

      The javadoc says: "Up to three letters of 'D' can be specified."
      So this implies that it is legal to specify two letters of 'D' & the above is effectively a bug.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Execute the attached test case & observe the difference in exepcted and actual result.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      output is:
      true
      true
      true
      ACTUAL -
      output is:
      false
      false
      false

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------

      import java.time.LocalDate;
      import java.time.format.DateTimeFormatter;
      import java.time.format.DateTimeParseException;

      public class BugTest {

      private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("DD yyyy");

      public static void main(String[] args) {
      System.out.println(isParsable("003 1980"));
      System.out.println(isParsable("023 1980"));
      System.out.println(isParsable("123 1980"));
      }

      private static boolean isParsable(String input) {
      try {
      LocalDate.parse(input, FORMATTER);
      return true;
      } catch (DateTimeParseException e) {
      return false;
      }
      }

      }

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

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                ntv Nadeesh Tv
                Reporter:
                webbuggrp Webbug Group
              • Votes:
                0 Vote for this issue
                Watchers:
                7 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: