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

FilterOutputStream ignores IOException from flush() in close()

    XMLWordPrintable

Details

    • Bug
    • Resolution: Duplicate
    • P4
    • None
    • 6u24
    • core-libs
    • x86
    • linux

    Description

      FULL PRODUCT VERSION :
      java version "1.6.0_22"
      Java(TM) SE Runtime Environment (build 1.6.0_22-b04-307-10M3261)
      Java HotSpot(TM) 64-Bit Server VM (build 17.1-b03-307, mixed mode)


      A DESCRIPTION OF THE PROBLEM :
      When calling close() on FilterOutputStream, the stream flushes the underlying stream, but discards any IOException resulting from the flush.

      This means that using e.g a BufferedOutputStream to write to an OutputStream can appear to have succeeded where in fact it failed: the underlying stream crashed during the flush, and the exception was swallowed.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      (See source code.)

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The program should throw an IOException.
      ACTUAL -
      The program ran and terminated with no exception thrown.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      package bufferedoutputstreamtest;

      import java.io.BufferedOutputStream;
      import java.io.IOException;
      import java.io.OutputStream;

      public class Main {
          public static void main(String[] args) throws IOException {
      OutputStream crashy = new OutputStream() {
      @Override
      public void write(int i) throws IOException {
      System.out.println("CRASHING NOW");
      throw new IOException("crash");
      }
      };
      BufferedOutputStream bos = new BufferedOutputStream(crashy);
      bos.write(33);
      bos.close();
          }
      }

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

      CUSTOMER SUBMITTED WORKAROUND :
      Flushing the outputstream before closing it correctly triggers the exception.

      Attachments

        Issue Links

          Activity

            People

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

              Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: