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

java.time.format.DateTimeFormatter can't parse localized zone-offset

    Details

    • Subcomponent:
    • Resolved In Build:
      b116
    • CPU:
      generic
    • OS:
      generic

      Description

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

      ADDITIONAL OS VERSION INFORMATION :
      Mac OS 10.11.1

      A DESCRIPTION OF THE PROBLEM :
      The DateTimeFormatter fails to parse its own output for format strings containing "O". The following code throws a StringIndexOutOfBoundsException on the final line.

      import java.time.ZoneOffset
      import java.time.ZonedDateTime
      import java.time.format.DateTimeFormatter
      DateTimeFormatter formatter = DateTimeFormatter
              .ofPattern("yyyy-MM-dd'T'HH:mm:ss.S O")
              .withLocale(Locale.ENGLISH)
      String date = formatter.format(ZonedDateTime.now(ZoneOffset.UTC));
      formatter.parse(date)

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      import java.time.ZoneOffset
      import java.time.ZonedDateTime
      import java.time.format.DateTimeFormatter
      DateTimeFormatter formatter = DateTimeFormatter
              .ofPattern("yyyy-MM-dd'T'HH:mm:ss.S O")
              .withLocale(Locale.ENGLISH)
      String date = formatter.format(ZonedDateTime.now(ZoneOffset.UTC));
      formatter.parse(date)

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Successful parse
      ACTUAL -
      StringIndexOutOfBoundsException

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      java.time.format.DateTimeParseException: Text '2016-04-08T10:49:52.7 GMT' could not be parsed: String index out of range: 25

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.time.ZoneOffset
      import java.time.ZonedDateTime
      import java.time.format.DateTimeFormatter
      DateTimeFormatter formatter = DateTimeFormatter
              .ofPattern("yyyy-MM-dd'T'HH:mm:ss.S O")
              .withLocale(Locale.ENGLISH)
      String date = formatter.format(ZonedDateTime.now(ZoneOffset.UTC));
      formatter.parse(date)
      ---------- END SOURCE ----------

        Issue Links

          Activity

          Hide
          psonal Pallavi Sonal added a comment -
          Attached test case executed on:
          JDK 8 - Fail
          JDK 8u77 - Fail
          JDK 9EA - Fail

          The following exception is thrown in each case:
          Exception in thread "main" java.time.format.DateTimeParseException: Text '2016-04-12T07:53:19.9 GMT' could not be parsed: String index out of range: 25
                  at java.time.format.DateTimeFormatter.createError(java.base@9-ea/DateTimeFormatter.java:1932)
                  at java.time.format.DateTimeFormatter.parse(java.base@9-ea/DateTimeFormatter.java:1793)
                  at JI9034761.main(JI9034761.java:13)
          Caused by: java.lang.StringIndexOutOfBoundsException: String index out of range: 25
                  at java.lang.StringLatin1.charAt(java.base@9-ea/StringLatin1.java:45)
                  at java.lang.String.charAt(java.base@9-ea/String.java:701)
                  at java.time.format.DateTimeFormatterBuilder$LocalizedOffsetIdPrinterParser.parse(java.base@9-ea/DateTimeFormatterBuilder.java:3553)
                  at java.time.format.DateTimeFormatterBuilder$CompositePrinterParser.parse(java.base@9-ea/DateTimeFormatterBuilder.java:2212)
                  at java.time.format.DateTimeFormatter.parseUnresolved0(java.base@9-ea/DateTimeFormatter.java:2022)
                  at java.time.format.DateTimeFormatter.parseResolved0(java.base@9-ea/DateTimeFormatter.java:1951)
                  at java.time.format.DateTimeFormatter.parse(java.base@9-ea/DateTimeFormatter.java:1789)
                  ... 1 more
          Show
          psonal Pallavi Sonal added a comment - Attached test case executed on: JDK 8 - Fail JDK 8u77 - Fail JDK 9EA - Fail The following exception is thrown in each case: Exception in thread "main" java.time.format.DateTimeParseException: Text '2016-04-12T07:53:19.9 GMT' could not be parsed: String index out of range: 25         at java.time.format.DateTimeFormatter.createError( java.base@9-ea /DateTimeFormatter.java:1932)         at java.time.format.DateTimeFormatter.parse( java.base@9-ea /DateTimeFormatter.java:1793)         at JI9034761.main(JI9034761.java:13) Caused by: java.lang.StringIndexOutOfBoundsException: String index out of range: 25         at java.lang.StringLatin1.charAt( java.base@9-ea /StringLatin1.java:45)         at java.lang.String.charAt( java.base@9-ea /String.java:701)         at java.time.format.DateTimeFormatterBuilder$LocalizedOffsetIdPrinterParser.parse( java.base@9-ea /DateTimeFormatterBuilder.java:3553)         at java.time.format.DateTimeFormatterBuilder$CompositePrinterParser.parse( java.base@9-ea /DateTimeFormatterBuilder.java:2212)         at java.time.format.DateTimeFormatter.parseUnresolved0( java.base@9-ea /DateTimeFormatter.java:2022)         at java.time.format.DateTimeFormatter.parseResolved0( java.base@9-ea /DateTimeFormatter.java:1951)         at java.time.format.DateTimeFormatter.parse( java.base@9-ea /DateTimeFormatter.java:1789)         ... 1 more
          Hide
          ntv Nadeesh Tv (Inactive) added a comment -
          Issue in LocalizedOffsetIdPrinterParser.parse method
          Show
          ntv Nadeesh Tv (Inactive) added a comment - Issue in LocalizedOffsetIdPrinterParser.parse method
          Show
          ntv Nadeesh Tv (Inactive) added a comment - http://mail.openjdk.java.net/pipermail/core-libs-dev/2016-April/040150.html
          Hide
          hgupdate HG Updates added a comment -
          URL: http://hg.openjdk.java.net/jdk9/dev/jdk/rev/788f3987f53b
          User: ntv
          Date: 2016-04-21 17:52:57 +0000
          Show
          hgupdate HG Updates added a comment - URL: http://hg.openjdk.java.net/jdk9/dev/jdk/rev/788f3987f53b User: ntv Date: 2016-04-21 17:52:57 +0000
          Hide
          hgupdate HG Updates added a comment -
          URL: http://hg.openjdk.java.net/jdk9/jdk9/jdk/rev/788f3987f53b
          User: lana
          Date: 2016-04-27 18:46:47 +0000
          Show
          hgupdate HG Updates added a comment - URL: http://hg.openjdk.java.net/jdk9/jdk9/jdk/rev/788f3987f53b User: lana Date: 2016-04-27 18:46:47 +0000

            People

            • Assignee:
              ntv Nadeesh Tv (Inactive)
              Reporter:
              webbuggrp Webbug Group
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: