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

DeflaterOutputStream.finish() closes the underlying Deflater if an IOException is thrown

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P4 P4
    • tbd
    • 8
    • core-libs
    • None

      The DeflaterOutputStream specifies that it will create a Deflater of its own when the stream is constructed without any given Deflater. It further specifies that this Deflater, that it created, will be closed when the stream is closed (i.e. close() is called on the DeflaterOutputStream).

      However, in the current implementation of DeflaterOutputStream.finish() method, such a Deflater instance is also closed if finish() throws an IOException:

      public void finish() throws IOException {
          if (!def.finished()) {
              try{
                  def.finish();
                  while (!def.finished()) {
                      deflate();
                  }
              } catch(IOException e) {
                  if (usesDefaultDeflater)
                      def.end();
                  throw e;
              }
          }
      }

      This needs to be reviewed to either specify this behaviour or change the implementation to not close the Deflater instance.

            jpai Jaikiran Pai
            jpai Jaikiran Pai
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: