JDK-8038486 : DateTimeFormatter requires a PERIOD character to parse a fraction-of-second.
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.time
  • Affected Version: 8
  • Priority: P4
  • Status: Resolved
  • Resolution: Duplicate
  • OS: os_x
  • CPU: x86
  • Submitted: 2014-03-24
  • Updated: 2014-04-19
  • Resolved: 2014-04-19
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
tbd_minorResolved
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
java version "1.8.0"
Java(TM) SE Runtime Environment (build 1.8.0-b132)
Java HotSpot(TM) 64-Bit Server VM (build 25.0-b70, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Mac OS X 10.8.5 (Mountain Lion).

A DESCRIPTION OF THE PROBLEM :
In the new java.time package, the documentation for the DateTimeFormatter class describes fraction-of-second as just another part of a date-time like any other part. Yet it treats fraction-of-second as special when parsing a string: A PERIOD character is required. Without a "." in the input string being parsed, and in the format pattern, an exception is thrown. The documentation says nothing about a period being required.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
This code works:

String input = "20111203123456"; 
DateTimeFormatter formatter = DateTimeFormatter.ofPattern( "yyyyMMddHHmmss");
LocalDateTime localDateTime = LocalDateTime.parse( input, formatter );

Rendering: 

2011-12-03T12:34:56

But when adding the uppercase "S" for fraction of second, an exception is thrown. This code:

String input = "2011120312345655"; 
DateTimeFormatter formatter = DateTimeFormatter.ofPattern( "yyyyMMddHHmmssSS");
LocalDateTime localDateTime = LocalDateTime.parse( input, formatter );

throws this exception:

java.time.format.DateTimeParseException: Text '2011120312345655' could not be parsed at index 0

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I expected this string:

2011-12-03T12:34:56.55
ACTUAL -
Throws this exception:

java.time.format.DateTimeParseException: Text '2011120312345655' could not be parsed at index 0

ERROR MESSAGES/STACK TRACES THAT OCCUR :
java.time.format.DateTimeParseException: Text '2011120312345655' could not be parsed at index 0

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
String input = "2011120312345655"; 
DateTimeFormatter formatter = DateTimeFormatter.ofPattern( "yyyyMMddHHmmssSS");
LocalDateTime localDateTime = LocalDateTime.parse( input, formatter );
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
None. A string without punctuation for the fraction-of-second cannot be parsed.


Comments
Duplicate of JDK-8031085.
19-04-2014

Additional testing was performed: yyyy SSMMddHHmmss - works SSyyyyMMddHHmmss - works yyyyMMddHHmmss.SS - works (as stated in report) yyyyMMddHHmmss SS - works yyyySSMMddHHmmss - fails with exception yyyyMMddHHmmssSS - fails with exception
27-03-2014