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

XMLWordPrintable

    • Type: Bug
    • Resolution: Unresolved
    • Priority: P4
    • tbd
    • Affects Version/s: 8
    • Component/s: 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.

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

              Created:
              Updated: