Details
-
Bug
-
Status: Closed
-
Minor
-
Resolution: Fixed
-
None
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.