< prev index next >

src/java.base/share/classes/java/lang/String.java

Print this page
rev 53050 : 8215493: String::indent inconsistency with blank lines
Reviewed-by: rriggs, smarks

@@ -2811,12 +2811,11 @@
      * {@link String#lines()}. Each line is then adjusted as described below
      * and then suffixed with a line feed {@code "\n"} (U+000A). The resulting
      * lines are then concatenated and returned.
      * <p>
      * If {@code n > 0} then {@code n} spaces (U+0020) are inserted at the
-     * beginning of each line. {@link String#isBlank() Blank lines} are
-     * unaffected.
+     * beginning of each line.
      * <p>
      * If {@code n < 0} then up to {@code n}
      * {@link Character#isWhitespace(int) white space characters} are removed
      * from the beginning of each line. If a given line does not contain
      * sufficient white space then all leading

@@ -2847,11 +2846,11 @@
     private String indent(int n, boolean removeBlanks) {
         Stream<String> stream = removeBlanks ? lines(Integer.MAX_VALUE, Integer.MAX_VALUE)
                                              : lines();
         if (n > 0) {
             final String spaces = " ".repeat(n);
-            stream = stream.map(s -> s.isBlank() ? s : spaces + s);
+            stream = stream.map(s -> spaces + s);
         } else if (n == Integer.MIN_VALUE) {
             stream = stream.map(s -> s.stripLeading());
         } else if (n < 0) {
             stream = stream.map(s -> s.substring(Math.min(-n, s.indexOfNonWhitespace())));
         }
< prev index next >