JDK-8208164 : (str) improve specification of String::lines
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.lang
  • Affected Version: 11
  • Priority: P2
  • Status: Closed
  • Resolution: Fixed
  • Submitted: 2018-07-24
  • Updated: 2018-08-09
  • Resolved: 2018-07-26
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 11 JDK 12
11 b25Fixed 12Fixed
Related Reports
CSR :  
Relates :  
Description
The definitions for "line terminator," and "line" given in the specification for String.lines() could be improved.
Comments
Suggested fix: # HG changeset patch # User smarks # Date 1532475564 25200 # Tue Jul 24 16:39:24 2018 -0700 # Node ID 38b0fbbbe9b5243a5acd9369a000be4e079229e2 # Parent 049b2037b5d804a09829fcdcd889378b39b5a75f 8208164: improve specification for String.lines() diff -r 049b2037b5d8 -r 38b0fbbbe9b5 src/java.base/share/classes/java/lang/String.java --- a/src/java.base/share/classes/java/lang/String.java Tue Jul 24 12:12:16 2018 -0700 +++ b/src/java.base/share/classes/java/lang/String.java Tue Jul 24 16:39:24 2018 -0700 @@ -2764,30 +2764,32 @@ } /** - * Returns a stream of substrings extracted from this string - * partitioned by line terminators. + * Returns a stream of lines extracted from this string, + * separated by line terminators. * <p> - * Line terminators recognized are line feed - * {@code "\n"} ({@code U+000A}), - * carriage return - * {@code "\r"} ({@code U+000D}) - * and a carriage return followed immediately by a line feed - * {@code "\r\n"} ({@code U+000D U+000A}). + * A <i>line terminator</i> is one of the following: + * a line feed character {@code "\n"} (U+000A), + * a carriage return character {@code "\r"} (U+000D), + * or a carriage return followed immediately by a line feed + * {@code "\r\n"} (U+000D U+000A). * <p> - * The stream returned by this method contains each line of - * this string that is terminated by a line terminator except that - * the last line can either be terminated by a line terminator or the - * end of the string. - * The lines in the stream are in the order in which - * they occur in this string and do not include the line terminators - * partitioning the lines. + * A <i>line</i> is either a sequence of zero or more characters + * followed by a line terminator, or it is a sequence of one or + * more characters followed by the end of the string. A + * line does not include the line terminator. + * <p> + * The stream returned by this method contains the lines from + * this string in the order in which they occur. + * + * @apiNote This definition of <i>line</i> implies that an empty + * string has zero lines and that there is no empty line + * following a line terminator at the end of a string. * * @implNote This method provides better performance than * split("\R") by supplying elements lazily and * by faster search of new line terminators. * - * @return the stream of strings extracted from this string - * partitioned by line terminators + * @return the stream of lines extracted from this string * * @since 11 */
25-07-2018

P2 since this method is new in JDK 11 and it's important to get right. In addition, several follow-on methods will be relying on the definitions provided here, so it's important to get this in. This is intended to be a spec-only change, to clarify and make the specification more precise. The implementation should not need to be changed in response to this spec change.
25-07-2018