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

Invoking ConsoleHandler.setOutputStream(...) closes System.err

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Future Project
    • Icon: P4 P4
    • None
    • 1.4.1
    • core-libs

      Name: nt126004 Date: 03/04/2003


      FULL PRODUCT VERSION :
      java version "1.4.1"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1-b21)
      Java HotSpot(TM) Client VM (build 1.4.1-b21, mixed mode)

      FULL OPERATING SYSTEM VERSION :
      Microsoft Windows 2000 [Version 5.00.2195]

      ADDITIONAL OPERATING SYSTEMS :
      French language version


      A DESCRIPTION OF THE PROBLEM :
      Some users find unfortunate that ConsoleHandler log to
      System.err instead of System.out. A workaround is to
      subclass ConsoleHandler and invoke
      setOutputStream(System.out) in the constructor. Note that
      ConsoleHandler override the close() method in order to avoid
      closing System.err. See:

      http://java.sun.com/j2se/1.4/docs/api/java/util/logging/ConsoleHandler.html#close()

      Unfortunately, StreamHandler.setOutputStream(...) does not
      invokes close(). It invokes flushAndClose() instead, which
      is a private method (see StreamHandler.java at line 111).
      The flushAndClose() implementation invokes unconditionally
      the OutputStream.close() method (see line 243).


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the test case below.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED:
      Test A
      Test B

      ACTUAL:
      Test A


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.util.logging.*;

      public class Test extends ConsoleHandler
      {
          public Test()
          {
              setOutputStream(System.out);
          }

          public static void main(String[] args)
          {
              System.err.println("Test A");
              new Test();
              System.err.println("Test B");
              System.err.flush();
          }
      }

      ---------- END SOURCE ----------

      CUSTOMER WORKAROUND :
      Do not subclass ConsoleHandler. Console StreamHandler instead.
      (Review ID: 160819)
      ======================================================================

            Unassigned Unassigned
            nthompsosunw Nathanael Thompson (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: