Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8230436

String.stripIndent() javadoc unclear about LF/CR at end of string

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P4 P4
    • tbd
    • 13
    • core-libs
    • None

      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().


            aleonard Andrew Leonard
            aleonard Andrew Leonard
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: