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

FilterOutputStream.close() silently ignores flush() exceptions

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P3
    • Resolution: Won't Fix
    • Affects Version/s: 5.0
    • Fix Version/s: None
    • Component/s: core-libs
    • Labels:
    • Subcomponent:
    • CPU:
      x86
    • OS:
      windows_xp

      Description

      FULL PRODUCT VERSION :
      Tested in 1.5.0_02-b09

      ADDITIONAL OS VERSION INFORMATION :
      Appears to be a problem in Java library, so applicable to all OSs.

      A DESCRIPTION OF THE PROBLEM :
      FilterOutputStream silently ignores exceptions when doing a flush on close.
      This can hide IO problems such a full disk. The particular case where it got
      me was using a ZipOutputStream over a BufferedOutputStream.


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.io.*;
      import java.util.zip.*;
      class test
      {
        static class LimitOutputStream extends OutputStream
        {
          public void write(int n) throws IOException
          {
            num++;
            check();
          }

          public void write(byte[] buf) throws IOException
          {
            num += buf.length;
            check();
          }
          
          public void write(byte[] buf, int off, int len) throws IOException
          {
            num += len;
            check();
          }

          void check() throws IOException
          {
            if (num > 80)
            {
              //System.out.println("Limit.check: " + num);
              //Thread.dumpStack();
              throw new IOException("all full!");
            }
          }
              
          int num;
        }
        
        public static void main(String[] args)
          throws Exception
        {
          ZipOutputStream out =
            new ZipOutputStream(
            new BufferedOutputStream(
            new LimitOutputStream()));
          out.putNextEntry(new ZipEntry("entry"));
          for(int i=0; i<10000; ++i)
            out.write(new byte[100]);
          out.closeEntry();
          // out.flush(); without this line the close appears to silently work
          out.close();
        }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      You must explicitly flush() before close() if want to have an underlying
      exception raised.

      Release Regression From : 1.4.2_09
      The above release value was the last known release where this
      bug was known to work. Since then there has been a regression.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                iris Iris Clark
                Reporter:
                ndcosta Nelson Dcosta
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: