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

(fmt) Print{Stream,Writer} flushing behaviour is inconsistent

XMLWordPrintable

    • b59
    • generic
    • generic

      The new Print{Stream,Writer} convenience constructors added for formatting
      are inconsistent with respect to flushing. All state that there is no
      automatic line flushing; however, this likely not what's actually implemented.

      From ###@###.###:

      Stream flushing is a little odd. PrintWriter only flushes when a newline is
      written, so

        PrintWriter.printf("Hello");

      should *not* autoflush, while one can argue that

        PrintStream.printf("Hello");

      *should* autoflush because

        PrintStream.print("Hello");

      does.

      The flushing behavior in these classes is weird and inconsistent, but we
      need to try to not introduce any more.

      PrintWriter class doc goes out of its way to point out how its flushing
      behavior is different from PrintStream's.

      In an ideal world, we would want, for any output stream s,

      changing

        s.print("foo")
      to
        s.printf("foo")

      and

        s.println("foo")
      to
        s.printf("foo%n")

      should have no observable effect, including with regard to stream flushing.

            iris Iris Clark
            iris Iris Clark
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: