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

Minor mistakes in docs of PrintStream.append()

XMLWordPrintable

    • b18
    • generic
    • generic

      A DESCRIPTION OF THE PROBLEM :
      1. Simple typo: In the documentation of PrintStream.append(CharSequence) (https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/io/PrintStream.html#append(java.lang.CharSequence)), "invoking then" should be changed to "invoking the". (The surrounding text is "For instance, invoking then toString method of a character buffer will return ...".)

      2. The doc for PrintStream.append(CharSequence) says it "An invocation of this method of the form `out.append(csq)` behaves in exactly the same way as the invocation `out.print(csq.toString())`". That's technically incorrect, because if csq is null then the former prints "null" (as stated later in the doc) while the latter throws a NullPointerException.
      There are similar issues with PrintStream.append(CharSequence,int,int), PrintWriter(CharSequence), and PrintWriter.append(CharSequence,int,int).
      I'm not sure how this should be fixed.

      My first thought was to change the second snippet to `out.print(String.valueOf(csq))` (which matches the implementation), but that approach wouldn't work for append(CharSequence,int,int), and it places more cognitive load on the reader (they need to know the behaviour of String.valueOf(Object)).
      My second idea is to just drop the word "exactly", to indicate that it's only a rough equivalent.

      (Both of these issues have existed since the very first version of PrintStream.)

            bpb Brian Burkhalter
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: