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

Correct the documentation of PrintWriter to refer to System.lineSeparator

    XMLWordPrintable

    Details

    • Type: CSR
    • Status: Closed
    • Priority: P4
    • Resolution: Approved
    • Fix Version/s: 13
    • Component/s: core-libs
    • Labels:
      None
    • Subcomponent:
    • Compatibility Kind:
      behavioral
    • Compatibility Risk:
      minimal
    • Compatibility Risk Description:
      System.lineSeparator(), not the line.separator system property, is already used internally by PrintWriter.println() so there should be no compatibility risk.
    • Interface Kind:
      Java API
    • Scope:
      SE

      Description

      Summary

      Change specification of java.io.PrintWriter to refer to System.lineSeparator() instead of to the system property line.separator.

      Problem

      PrintWriter.println() refers to the system property line.separator instead of to System.lineSeparator() which is actually used internally. Conceivably the value of the property could change but the value returned by lineSeparator() will not.

      Solution

      Change the specification of PrintWriter.println() to:

      Terminates the current line by writing the line separator string. The line separator is System.lineSeparator() and is not necessarily a single newline character ('\n').

      Specification

      --- a/src/java.base/share/classes/java/io/PrintWriter.java
      +++ b/src/java.base/share/classes/java/io/PrintWriter.java
      @@ -1,5 +1,5 @@
       /*
      - * Copyright (c) 1996, 2017, Oracle and/or its affiliates. All rights reserved.
      + * Copyright (c) 1996, 2019, Oracle and/or its affiliates. All rights reserved.
        * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
        *
        * This code is free software; you can redistribute it and/or modify it
      @@ -704,9 +704,8 @@
      
           /**
            * Terminates the current line by writing the line separator string.  The
      -     * line separator string is defined by the system property
      -     * {@code line.separator} and is not necessarily a single newline
      -     * character ({@code '\n'}).
      +     * line separator is {@link System#lineSeparator()} and is not necessarily
      +     * a single newline character ({@code '\n'}).
            */
           public void println() {
               newLine();

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              bpb Brian Burkhalter
              Reporter:
              rriggs Roger Riggs
              Reviewed By:
              Roger Riggs
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: