JDK-8025507 : LocalDateTime.parse(str, frmt) fails with Unable to obtain from TemporalAccessor
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.time
  • Affected Version: 8
  • Priority: P3
  • Status: Resolved
  • Resolution: Not an Issue
  • OS: windows_7
  • Submitted: 2013-09-26
  • Updated: 2013-10-01
  • Resolved: 2013-09-30
Related Reports
Relates :  
Description
FULL PRODUCT VERSION :
java version "1.8.0-ea"
Java(TM) SE Runtime Environment (build 1.8.0-ea-b108)
Java HotSpot(TM) 64-Bit Server VM (build 25.0-b50, mixed mode)

FULL OS VERSION :
Microsoft Windows [Version 6.1.7601]

A DESCRIPTION OF THE PROBLEM :
trying to create a Offset/LocalDateTime object from a given date/time string and a date/time format based on Patterns for Formatting and Parsing from DateTimeFormatter fails when attempting to parse the ZoneOffset value

THE PROBLEM WAS REPRODUCIBLE WITH -Xint FLAG: Did not try

THE PROBLEM WAS REPRODUCIBLE WITH -server FLAG: Did not try

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Create the string variable containing the actual Date/Time

    private String strDate = "2013-06-14T12:04:36.454-04:00";

Create the string variable holding the pattern to be used by the formatter

    private static String datePattern = "yyyy-MM-dd'T'hh:mm:ss.SSSXXX";

Create the DateTimeFormatter object

    private DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern(datePattern);

Attempt to create a LocalDateTime object from the strDate and dateFormatter

    private LocalDateTime ldtDate = LocalDateTime.parse(strDate, dateFormatter);

EXPECTED VERSUS ACTUAL BEHAVIOR :
When it seems that the Pattern syntax is correct to read the given string the following Error is thrown

Text '2013-06-14T12:04:36.454-04:00' could not be parsed: Unable to obtain LocalDateTime from TemporalAccessor: class java.time.format.Parsed
file:/D:/Oracle/Projects/UltraLogMiner/dist/run641707932/UltraLogMiner.jar!/com/ultra/log/miner/fxml/UltraLogMiner.fxml:14
  at java.time.format.DateTimeFormatter.createError(DateTimeFormatter.java:1919)
  at java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:1854)
  at java.time.LocalDateTime.parse(LocalDateTime.java:483)
  at com.my.program....
REPRODUCIBILITY :
This bug can be reproduced always.
Comments
As in Stephen Colebourne's comment the test case is incorrect.
30-09-2013

I don't know why my name is showing up as the reporter of this issue, I only spotted it in the JI project (for issues reported via bugs.sun.com) and moved it to the JDK project.
26-09-2013

The code is working correctly, but the error message needs improvement. You have requested a formatter for letter "h" which corresponds to clock-hour-of-am-pm (1 to 12). That letter cannot be used to form a complete time without also specifying the AM/PM letter "a". You probably wanted to use "H", which is the hour-of-day from 0 to 23.
26-09-2013