JDK-8057798 : java.time.format.DateTimeFormatter error in API doc example
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.time
  • Affected Version: 8u20
  • Priority: P4
  • Status: Resolved
  • Resolution: Duplicate
  • OS: windows_8
  • CPU: x86
  • Submitted: 2014-09-05
  • Updated: 2014-11-13
  • Resolved: 2014-11-13
Related Reports
Duplicate :  
Description
A DESCRIPTION OF THE PROBLEM :
The API docs for DateTimeFormatter explains: "The main date-time classes provide two methods - one for formatting, format(DateTimeFormatter formatter), and one for parsing, parse(CharSequence text, DateTimeFormatter formatter)."

Then there is an example:

String text = date.toString(formatter);
LocalDate date = LocalDate.parse(text, formatter);

Error: date.toString(formatter); should be: date.format(formatter);

As explained in the text above there is a "format" method, there is no "toString" method that takes a DateTimeFormatter.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
String text = date.format(formatter);
ACTUAL -
String text = date.toString(formatter);

URL OF FAULTY DOCUMENTATION :
http://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html