Uploaded image for project: 'Jackrabbit Oak'
  1. Jackrabbit Oak
  2. OAK-6707

TarWriter.close() must not throw an exception on subsequent invocations

    XMLWordPrintableJSON

Details

    Description

      Invoking TarWriter.close() on an already closed writer throws an ISE. According to the general contract this is not allowed:

      * Closes this stream and releases any system resources associated
      * with it. If the stream is already closed then invoking this
      * method has no effect.
      

      We should adjust the behvaviour of that method accordingly.

      Failing to comply with that general contract causes TarWriter instances to fail in try-resource statements when multiple wrapped streams are involved.

      Consider

      try (
          StringWriter string = new StringWriter();
          PrintWriter writer = new PrintWriter(string);
          WriterOutputStream out = new WriterOutputStream(writer, Charsets.UTF_8))
      {
          dumpHeader(out);
          writer.println("----------------------------------------");
          dumpHex(out);
          writer.println("----------------------------------------");
          return string.toString();
      }
      

      This code would cause exceptions to be thrown if e.g. the PrintWriter.close method would not be idempotent.

      Attachments

        Activity

          People

            mduerig Michael Dürig
            mduerig Michael Dürig
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: