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

PrintStream.write(char[]) should only need to flush once when char[] contains several newlines

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Unresolved
    • Icon: P5 P5
    • None
    • 7
    • core-libs
    • x86
    • windows_xp

      FULL PRODUCT VERSION :


      A DESCRIPTION OF THE PROBLEM :
      In java.io.PrintStream.write(char[] buf): out.flush() is called for every found '\n' char in buf while it should be enough to call it only once (if buf contains '\n').

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Consider the following code:

      System.out.print(new char[] { '\n', '\n'});

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      out.flush() is called twice.
      ACTUAL -
      out.flush() should be called once.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      CUSTOMER SUBMITTED WORKAROUND :
      if (autoFlush) {
      for (int i = 0; i < buf.length; i++)
      if (buf[i] == '\n')
      out.flush();
      }

      ->

      if (autoFlush) {
      for (int i = 0; i < buf.length; i++)
      if (buf[i] == '\n') {
      out.flush();
      break;
      }
      }

            Unassigned Unassigned
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Imported:
              Indexed: