JDK-8202144 : DateTimeFormatter fail to parse time string when seconds and milliseconds are 0s
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.time
  • Affected Version: 10.0.1
  • Priority: P4
  • Status: Closed
  • Resolution: Not an Issue
  • OS: windows_10
  • CPU: x86_64
  • Submitted: 2018-04-22
  • Updated: 2018-04-23
  • Resolved: 2018-04-23
Description
A DESCRIPTION OF THE PROBLEM :
As already mention in this Question in 

StackOveflow https://stackoverflow.com/questions/49967139/java-datetimeformatter-fail-to-parse-time-string-when-seconds-and-milliseconds

This piece of code should return for this "20180301091600000" with this "yyyyMMddHHmmssSSS" patter a result : "2018-03-01T09:16:00.000" note the last part "00.000" for seconds and milliseconds.
Instead it return "2018-03-01T09:16".


REGRESSION : Last worked in version 10.0.1

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
DateTimeFormatter dtformatter = DateTimeFormatter.ofPattern("yyyyMMddHHmmssSSS");
var result = LocalDateTime.parse("20180301091600000", dtformatter);
System.out.println(result);

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
2018-03-01T09:16:00.000
ACTUAL -
2018-03-01T09:16

CUSTOMER SUBMITTED WORKAROUND :
A temporary solution is like I mentioned here https://stackoverflow.com/a/49967274/5558072

We need to parse the date with another formatter like this :

var result = LocalDateTime.parse("20180301091600001", dtformatter)
                                    .format(DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss:SSS"));

FREQUENCY : always



Comments
This is as per the specification at : https://docs.oracle.com/javase/10/docs/api/java/time/LocalDateTime.html#toString() The output will be one of the following ISO-8601 formats: uuuu-MM-dd'T'HH:mm uuuu-MM-dd'T'HH:mm:ss uuuu-MM-dd'T'HH:mm:ss.SSS uuuu-MM-dd'T'HH:mm:ss.SSSSSS uuuu-MM-dd'T'HH:mm:ss.SSSSSSSSS *******The format used will be the shortest that outputs the full value of the time where the omitted parts are implied to be zero.****** (emphasis mine)
23-04-2018