Repository: commons-compress Updated Branches: refs/heads/master abc2d2390 -> 2424036c2
COMPRESS-357 - no longer invoke finish from finalize Project: http://git-wip-us.apache.org/repos/asf/commons-compress/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-compress/commit/2424036c Tree: http://git-wip-us.apache.org/repos/asf/commons-compress/tree/2424036c Diff: http://git-wip-us.apache.org/repos/asf/commons-compress/diff/2424036c Branch: refs/heads/master Commit: 2424036c286f0b3dfc280f00a1e835cb52e39375 Parents: abc2d23 Author: Stefan Bodewig <[email protected]> Authored: Wed Jun 15 06:16:39 2016 +0200 Committer: Stefan Bodewig <[email protected]> Committed: Wed Jun 15 06:16:39 2016 +0200 ---------------------------------------------------------------------- src/changes/changes.xml | 21 ++++++++--- .../bzip2/BZip2CompressorOutputStream.java | 39 ++++++++++---------- 2 files changed, 36 insertions(+), 24 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/commons-compress/blob/2424036c/src/changes/changes.xml ---------------------------------------------------------------------- diff --git a/src/changes/changes.xml b/src/changes/changes.xml index eb9bb00..fee6da3 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -43,7 +43,17 @@ The <action> type attribute can be add,update,fix,remove. </properties> <body> <release version="1.12" date="not released, yet" - description="Release 1.12 - API compatible to 1.11 but requires Java6 at runtime"> + description="Release 1.12 - API compatible to 1.11 but requires Java6 at runtime. +------------ + + + +Release 1.12 changes the behavior of BZip2CompressorOutputStream's +finalize method so that it no longer invokes finish. This is going to +break code that relied on the finalizer to clean up an unfinished +stream. The code will need to be changed to call finish or +close itself. +"> <action issue="COMPRESS-349" type="update" date="2016-04-09" dev="ggregory"> Update requirement from Java 5 to 6. </action> @@ -75,10 +85,6 @@ The <action> type attribute can be add,update,fix,remove. Snappy used by the IWA files contained within the zip archives used in Apple's iWork 13 files. </action> - <action issue="COMPRESS-357" type="fix" date="2016-05-26"> - BZip2CompressorOutputStream#finish is now synchronized to - avoid a race condition with the finalize method. - </action> <action issue="COMPRESS-351" type="update" date="2016-06-07"> ZipArchiveInputStream and CpioArchiveInputStream could throw exceptions who's messages contained potentially corrupt entry @@ -86,6 +92,11 @@ The <action> type attribute can be add,update,fix,remove. names by replacing unprintable characters and restricting the length to 255 characters. </action> + <action issue="COMPRESS-357" type="update" date="2016-06-15"> + BZip2CompressorOutputStream no longer tries to finish the + output stream in finalize. This is a breaking change for code + that relied on the finalizer. + </action> </release> <release version="1.11" date="2016-04-06" description="Release 1.11"> http://git-wip-us.apache.org/repos/asf/commons-compress/blob/2424036c/src/main/java/org/apache/commons/compress/compressors/bzip2/BZip2CompressorOutputStream.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/compress/compressors/bzip2/BZip2CompressorOutputStream.java b/src/main/java/org/apache/commons/compress/compressors/bzip2/BZip2CompressorOutputStream.java index 034fbfc..a26fac8 100644 --- a/src/main/java/org/apache/commons/compress/compressors/bzip2/BZip2CompressorOutputStream.java +++ b/src/main/java/org/apache/commons/compress/compressors/bzip2/BZip2CompressorOutputStream.java @@ -321,8 +321,8 @@ public class BZip2CompressorOutputStream extends CompressorOutputStream private Data data; private BlockSort blockSorter; - private final Object outLock = new Object(); private OutputStream out; + private volatile boolean closed; /** * Chooses a blocksize based on the given length of the data to compress. @@ -393,7 +393,7 @@ public class BZip2CompressorOutputStream extends CompressorOutputStream @Override public void write(final int b) throws IOException { - if (this.out != null) { + if (!closed) { write0(b); } else { throw new IOException("closed"); @@ -468,37 +468,38 @@ public class BZip2CompressorOutputStream extends CompressorOutputStream } /** - * Overriden to close the stream. + * Overriden to warn about an unclosed stream. */ @Override protected void finalize() throws Throwable { - finish(); + if (!closed) { + System.err.println("Unclosed BZip2CompressorOutputStream detected, will *not* close it"); + } super.finalize(); } public void finish() throws IOException { - synchronized(outLock) { - if (out != null) { - try { - if (this.runLength > 0) { - writeRun(); - } - this.currentChar = -1; - endBlock(); - endCompression(); - } finally { - this.out = null; + if (!closed) { + closed = true; + try { + if (this.runLength > 0) { + writeRun(); } + this.currentChar = -1; + endBlock(); + endCompression(); + } finally { + this.out = null; + this.blockSorter = null; + this.data = null; } } - this.blockSorter = null; - this.data = null; } @Override public void close() throws IOException { - if (out != null) { + if (!closed) { final OutputStream outShadow = this.out; finish(); outShadow.close(); @@ -628,7 +629,7 @@ public class BZip2CompressorOutputStream extends CompressorOutputStream + len + ") > buf.length(" + buf.length + ")."); } - if (this.out == null) { + if (closed) { throw new IOException("stream closed"); }
