java.time.format.DateTimeParseException: Text '2016-01-02T12:34:56,7Z' could not be parsed at index 19

JDK Bug System | Webbug Group | 8 months ago
tip
Your exception is missing from the Samebug knowledge base.
Here are the best solutions we found on the Internet.
Click on the to mark the helpful solution and get rewards for you help.
  1. 0

    FULL PRODUCT VERSION : java version "1.8.0_102" Java(TM) SE Runtime Environment (build 1.8.0_102-b14) Java HotSpot(TM) 64-Bit Server VM (build 25.102-b14, mixed mode) ADDITIONAL OS VERSION INFORMATION : Mac OS X 10.11.6 A DESCRIPTION OF THE PROBLEM : The `java.time.Instant` class fails to parse input with a comma such as "2016-01-02T12:34:56,7Z". The java.time classes handle ISO 8601 formats by default when parsing or generating Strings that represent date-time values. The ISO 8601 standard accepts a decimal mark of either a COMMA or a FULL STOP (period, dot), with a preference for the COMMA. Source: the Wikipedia page for ISO 8601. https://en.wikipedia.org/wiki/ISO_8601 So I would expect this to work: String inputDot = "2016-01-02T12:34:56.7Z"; Instant instantDot = Instant.parse ( inputDot ); …as well as this one… String inputComma = "2016-01-02T12:34:56,7Z"; Instant instantComma = Instant.parse ( inputComma ); The first one with a dot does indeed succeed, but the second one with a comma fails with a `DateTimeParseException`. Exception in thread "main" java.time.format.DateTimeParseException: Text '2016-01-02T12:34:56,7Z' could not be parsed at index 19 at java.time.format.DateTimeFormatter.parseResolved0(DateTimeFormatter.java:1949) at java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:1851) at java.time.Instant.parse(Instant.java:395) at com.example.javatimestuff.App4.doIt(App4.java:92) at com.example.javatimestuff.App4.main(App4.java:61) STEPS TO FOLLOW TO REPRODUCE THE PROBLEM : Run this code: String inputComma = "2016-01-02T12:34:56,7Z"; Instant instantComma = Instant.parse ( inputComma ); EXPECTED VERSUS ACTUAL BEHAVIOR : EXPECTED - Expect an `Instant` object to be instantiated. ACTUAL - java.time.format.DateTimeParseException ERROR MESSAGES/STACK TRACES THAT OCCUR : Exception in thread "main" java.time.format.DateTimeParseException: Text '2016-01-02T12:34:56,7Z' could not be parsed at index 19 at java.time.format.DateTimeFormatter.parseResolved0(DateTimeFormatter.java:1949) at java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:1851) at java.time.Instant.parse(Instant.java:395) at com.example.javatimestuff.App4.doIt(App4.java:92) at com.example.javatimestuff.App4.main(App4.java:61) REPRODUCIBILITY : This bug can be reproduced always. ---------- BEGIN SOURCE ---------- String inputComma = "2016-01-02T12:34:56,7Z"; Instant instantComma = Instant.parse ( inputComma ); ---------- END SOURCE ----------

    JDK Bug System | 8 months ago | Webbug Group
    java.time.format.DateTimeParseException: Text '2016-01-02T12:34:56,7Z' could not be parsed at index 19
  2. 0

    For example, I'm trying to receive an HTTP date header: {code}@RequestHeader(HttpHeaders.IF_MODIFIED_SINCE) Optional<Instant> ifModifiedSince{code} but this results in a conversion error {code} org.springframework.web.method.annotation.MethodArgumentTypeMismatchException: Failed to convert value of type [java.lang.String] to required type [java.util.Optional] at org.springframework.web.method.annotation.AbstractNamedValueMethodArgumentResolver.resolveArgument(AbstractNamedValueMethodArgumentResolver.java:115) at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:99) at org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:161) at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:128) ... 88 more Caused by: org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [@org.springframework.web.bind.annotation.RequestHeader java.time.Instant] for value 'Thu, 21 Apr 2016 17:11:08 +0100' at org.springframework.core.convert.support.ConversionUtils.invokeConverter(ConversionUtils.java:41) at org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:192) at org.springframework.core.convert.support.ObjectToOptionalConverter.convert(ObjectToOptionalConverter.java:75) at org.springframework.core.convert.support.ConversionUtils.invokeConverter(ConversionUtils.java:35) at org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:192) at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:173) at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:108) at org.springframework.beans.TypeConverterSupport.doConvert(TypeConverterSupport.java:64) at org.springframework.beans.TypeConverterSupport.convertIfNecessary(TypeConverterSupport.java:47) at org.springframework.validation.DataBinder.convertIfNecessary(DataBinder.java:688) at org.springframework.web.method.annotation.AbstractNamedValueMethodArgumentResolver.resolveArgument(AbstractNamedValueMethodArgumentResolver.java:107) ... 91 more Caused by: java.time.format.DateTimeParseException: Text 'Thu, 21 Apr 2016 17:11:08 +0100' could not be parsed at index 0 at java.time.format.DateTimeFormatter.parseResolved0(DateTimeFormatter.java:1949) at java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:1851) at java.time.Instant.parse(Instant.java:395) at org.springframework.format.datetime.standard.InstantFormatter.parse(InstantFormatter.java:40) at org.springframework.format.datetime.standard.InstantFormatter.parse(InstantFormatter.java:35) at org.springframework.format.support.FormattingConversionService$ParserConverter.convert(FormattingConversionService.java:194) at org.springframework.core.convert.support.ConversionUtils.invokeConverter(ConversionUtils.java:35) ... 101 more {code} I tried to add {{@DateTimeFormat}} but it is unwieldy - the only built-ins are ISO-8601 formats. It's not possible to specify Java 8's {{DataTimeFormatter.RFC_1123_DATE_TIME}} to this annotation. Given that all HTTP date/time headers should be using the RFC 1123 format, shouldn't that be the default for {{@RequestHeader}} conversion? There should at least be better formatter integration with {{java.time}} classes. I'm running in a Spring Boot 1.3.3 context, if that makes any difference.

    Spring JIRA | 11 months ago | James Howe
    org.springframework.web.method.annotation.MethodArgumentTypeMismatchException: Failed to convert value of type [java.lang.String] to required type [java.util.Optional]
  3. 0

    For example, I'm trying to receive an HTTP date header: {code}@RequestHeader(HttpHeaders.IF_MODIFIED_SINCE) Optional<Instant> ifModifiedSince{code} but this results in a conversion error {code} org.springframework.web.method.annotation.MethodArgumentTypeMismatchException: Failed to convert value of type [java.lang.String] to required type [java.util.Optional] at org.springframework.web.method.annotation.AbstractNamedValueMethodArgumentResolver.resolveArgument(AbstractNamedValueMethodArgumentResolver.java:115) at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:99) at org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:161) at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:128) ... 88 more Caused by: org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [@org.springframework.web.bind.annotation.RequestHeader java.time.Instant] for value 'Thu, 21 Apr 2016 17:11:08 +0100' at org.springframework.core.convert.support.ConversionUtils.invokeConverter(ConversionUtils.java:41) at org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:192) at org.springframework.core.convert.support.ObjectToOptionalConverter.convert(ObjectToOptionalConverter.java:75) at org.springframework.core.convert.support.ConversionUtils.invokeConverter(ConversionUtils.java:35) at org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:192) at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:173) at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:108) at org.springframework.beans.TypeConverterSupport.doConvert(TypeConverterSupport.java:64) at org.springframework.beans.TypeConverterSupport.convertIfNecessary(TypeConverterSupport.java:47) at org.springframework.validation.DataBinder.convertIfNecessary(DataBinder.java:688) at org.springframework.web.method.annotation.AbstractNamedValueMethodArgumentResolver.resolveArgument(AbstractNamedValueMethodArgumentResolver.java:107) ... 91 more Caused by: java.time.format.DateTimeParseException: Text 'Thu, 21 Apr 2016 17:11:08 +0100' could not be parsed at index 0 at java.time.format.DateTimeFormatter.parseResolved0(DateTimeFormatter.java:1949) at java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:1851) at java.time.Instant.parse(Instant.java:395) at org.springframework.format.datetime.standard.InstantFormatter.parse(InstantFormatter.java:40) at org.springframework.format.datetime.standard.InstantFormatter.parse(InstantFormatter.java:35) at org.springframework.format.support.FormattingConversionService$ParserConverter.convert(FormattingConversionService.java:194) at org.springframework.core.convert.support.ConversionUtils.invokeConverter(ConversionUtils.java:35) ... 101 more {code} I tried to add {{@DateTimeFormat}} but it is unwieldy - the only built-ins are ISO-8601 formats. It's not possible to specify Java 8's {{DataTimeFormatter.RFC_1123_DATE_TIME}} to this annotation. Given that all HTTP date/time headers should be using the RFC 1123 format, shouldn't that be the default for {{@RequestHeader}} conversion? There should at least be better formatter integration with {{java.time}} classes. I'm running in a Spring Boot 1.3.3 context, if that makes any difference.

    Spring JIRA | 11 months ago | James Howe
    org.springframework.web.method.annotation.MethodArgumentTypeMismatchException: Failed to convert value of type [java.lang.String] to required type [java.util.Optional]
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    GitHub comment 7#258703944

    GitHub | 5 months ago | soc
    java.time.format.DateTimeParseException: Text '2007-12-03T10:15:30+05' could not be parsed at index 19
  6. 0

    Java 8 date/time: instant, could not be parsed at index 19

    Stack Overflow | 2 months ago | maksim2020
    java.time.format.DateTimeParseException: Text '2016-09-18T12:17:21:000Z' could not be parsed at index 19

    Root Cause Analysis

    1. java.time.format.DateTimeParseException

      Text '2016-01-02T12:34:56,7Z' could not be parsed at index 19

      at java.time.format.DateTimeFormatter.parseResolved0()
    2. Java RT
      Instant.parse
      1. java.time.format.DateTimeFormatter.parseResolved0(DateTimeFormatter.java:1949)
      2. java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:1851)
      3. java.time.Instant.parse(Instant.java:395)
      3 frames
    3. com.example.javatimestuff
      App4.main
      1. com.example.javatimestuff.App4.doIt(App4.java:92)
      2. com.example.javatimestuff.App4.main(App4.java:61)
      2 frames