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

Class java.time.ZonedDateTime cannot parse all ISO 8601 date formats

    XMLWordPrintable

    Details

    • Subcomponent:
    • CPU:
      generic
    • OS:
      generic

      Description

      FULL PRODUCT VERSION :


      A DESCRIPTION OF THE PROBLEM :
      "public static ZonedDateTime parse(CharSequence text)" method from java.time.ZonedDateTime does fails to parse all ISO 8601 format.

      For example, ZonedDateTime.parse("2017-01-01T00:00:00.000+0000"); fails but ZonedDateTime.parse("2017-01-01T00:00:00.000+00:00"); works when both format should be accepted according to ISO-8601 requirements.

      C.f. https://en.wikipedia.org/wiki/ISO_8601 : "An offset of zero, in addition to having the special representation "Z", can also be stated numerically as "+00:00", "+0000", or "+00""

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
       ZonedDateTime.parse("2017-01-01T00:00:00.000+0000");

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Method should return a valid instance of class ZonedDateTime.
      ACTUAL -
      Method throws java.time.format.DateTimeParseException

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      java.time.format.DateTimeParseException: Text '2017-01-01T00:00:00.000+0000' could not be parsed at index 23

      at java.time.format.DateTimeFormatter.parseResolved0(DateTimeFormatter.java:1949)
      at java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:1851)
      at java.time.ZonedDateTime.parse(ZonedDateTime.java:597)
      at java.time.ZonedDateTime.parse(ZonedDateTime.java:582)

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
          public void test() {
              ZonedDateTime zonedDateTime = ZonedDateTime.parse("2017-01-01T00:00:00.000+0000");
          }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Use another time format

        Attachments

          Activity

            People

            Assignee:
            naoto Naoto Sato
            Reporter:
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: