JDK-8230436 : String.stripIndent() javadoc unclear about LF/CR at end of string
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.lang
  • Affected Version: 13
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • Submitted: 2019-09-02
  • Updated: 2019-09-10
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
tbdUnresolved
Related Reports
Relates :  
Description
The javadoc for String.stripIndent() states the following:
First, the individual lines of this string are extracted as if by using lines().
Then, the minimum indentation (min) is determined as follows. For each non-blank line (as defined by isBlank()), the leading white space characters are counted. The leading white space characters on the last line are also counted even if blank. The min value is the smallest of these counts. 

What is not immediately obvious from this due to the way it is worded possibly, is that if the input string ends with a LF (\n), that the min indent is then 0, as though lines() does not include that last "empty" line as a "line", it counts in determing the indent for stripIndent().

The significance of the following API Note is also perhaps not evident enough:
If this string ends with a line terminator then the result will end with a line terminator.

The following is not alway true either:
The line count of the result will be the same as line count of this string.
If the last line is white-space followed LF that gets removed by the indent, then the last line becomes <empty>LF, which does not count as a line any more for String.lines().