JDK-8160225 : java.time.format.DateTimeFormatter issues for month-of-year
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.time
  • Affected Version: 8
  • Priority: P4
  • Status: Closed
  • Resolution: Cannot Reproduce
  • OS: generic
  • CPU: x86_64
  • Submitted: 2016-06-23
  • Updated: 2019-08-02
  • Resolved: 2019-08-02
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.
JDK 8
8-poolResolved
Related Reports
Relates :  
Description
FULL PRODUCT VERSION :
this is probably irrelevant
java version "1.8.0_60"
Java(TM) SE Runtime Environment (build 1.8.0_60-b27)
Java HotSpot(TM) 64-Bit Server VM (build 25.60-b23, mixed mode)


ADDITIONAL OS VERSION INFORMATION :
3.19.0-61-generic #69~14.04.1-Ubuntu SMP Thu Jun 9 09:09:13 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux

EXTRA RELEVANT SYSTEM CONFIGURATION :
its really just appears to be a documentation bug

A DESCRIPTION OF THE PROBLEM :
your line:
M/L     month-of-year               number/text       7; 07; Jul; July; J

should probably be either:
M/L     month-of-year               text/number       7; 07; Jul; July; J
or
L/M     month-of-year               number/text       7; 07; Jul; July; J

the order of letters in the first column should reflect the order of values in the third column

REGRESSION.  Last worked in version 8u73

ADDITIONAL REGRESSION INFORMATION: 
it really just appears to be a documentation bug

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
import java.lang.String;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.time.ZonedDateTime;

class DTF {
    public static void main(String[] args) {
            String ds =    "Fri Apr 01 00:13:53 EDT 2016";
            String dtfmt = "EEE MMM dd HH:mm:ss z yyyy";
            System.err.println(dtfmt);

            DateTimeFormatter fmtr = DateTimeFormatter.ofPattern(dtfmt);
            ZonedDateTime date = ZonedDateTime.parse(ds, fmtr);

            String text = date.format(fmtr);
            System.err.println(text);
            System.err.println(date.toString());
    }
}


EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
since the string contains 'Apr', I expected that I should have used 'LLL' instead of 'MMM' to parse the
string.
In this case, I would expect a date parse exception such as this:
Exception in thread "main" java.time.format.DateTimeParseException: Text 'Fri Apr 01 00:13:53 EDT 2016' could not be parsed at index 4
	at java.time.format.DateTimeFormatter.parseResolved0(DateTimeFormatter.java:1949)
	at java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:1851)
	at java.time.ZonedDateTime.parse(ZonedDateTime.java:597)
	at DTF.main(DTF.java:15)

ACTUAL -
EEE MMM dd HH:mm:ss z yyyy
Fri Apr 01 00:13:53 EDT 2016
2016-04-01T00:13:53-04:00[America/New_York]


ERROR MESSAGES/STACK TRACES THAT OCCUR :
I got no error message with the format string "EEE MMM dd HH:mm:ss z yyyy"
with the format string "EEE LLL dd HH:mm:ss z yyyy", I get:
Exception in thread "main" java.time.format.DateTimeParseException: Text 'Fri Apr 01 00:13:53 EDT 2016' could not be parsed at index 4
	at java.time.format.DateTimeFormatter.parseResolved0(DateTimeFormatter.java:1949)
	at java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:1851)
	at java.time.ZonedDateTime.parse(ZonedDateTime.java:597)
	at DTF.main(DTF.java:15)


REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.lang.String;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.time.ZonedDateTime;

class DTF {
    public static void main(String[] args) {
            String ds =    "Fri Apr 01 00:13:53 EDT 2016";
            String dtfmt = "EEE MMM dd HH:mm:ss z yyyy";
            System.err.println(dtfmt);

            DateTimeFormatter fmtr = DateTimeFormatter.ofPattern(dtfmt);
            ZonedDateTime date = ZonedDateTime.parse(ds, fmtr);

            String text = date.format(fmtr);
            System.err.println(text);
            System.err.println(date.toString());
    }
}

---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
import java.lang.String;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.time.ZonedDateTime;

class DTF {
    public static void main(String[] args) {
            String ds =    "Fri Apr 01 00:13:53 EDT 2016";
            String dtfmt = "EEE MMM dd HH:mm:ss z yyyy";
            System.err.println(dtfmt);

            DateTimeFormatter fmtr = DateTimeFormatter.ofPattern(dtfmt);
            ZonedDateTime date = ZonedDateTime.parse(ds, fmtr);

            String text = date.format(fmtr);
            System.err.println(text);
            System.err.println(date.toString());
    }
}



Comments
Please take a look.
26-06-2016

As per the Java API documentation (https://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html ), "Number/Text: If the count of pattern letters is 3 or greater, use the Text rules above. Otherwise use the Number rules above." So, expectation of user is that whether MMM is used or LLL is used, the text rules should be used and the month should be displayed in short form. But two issues are observed here: a) When LLL is used , in JDK 8u versions it throws an exception: Output on JDK 8u92: Exception in thread "main" java.time.format.DateTimeParseException: Text 'Fri Apr 01 00:13:53 EDT 2016' 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.ZonedDateTime.parse(ZonedDateTime.java:597) at JI9040680.main(JI9040680.java:13) b) In JDK 9, the LLL is accepted and no exception is thrown, but the output is displayed as "2016-04-01T00:13:53-04:00[America/New_York]" , the expected result is that the month be displayed as Apr rather than in numeric form. Output on JDK 9: EEE LLL dd HH:mm:ss z yyyy Fri Apr 01 00:13:53 GMT-04:00 2016 2016-04-01T00:13:53-04:00[America/New_York]
24-06-2016