Revert "fix COMPRESS-357 with a volatile flag" This reverts commit 8769bb6980ea9d46f8fbec1fa1075128d6f61936.
Project: http://git-wip-us.apache.org/repos/asf/commons-compress/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-compress/commit/f87a7ce9 Tree: http://git-wip-us.apache.org/repos/asf/commons-compress/tree/f87a7ce9 Diff: http://git-wip-us.apache.org/repos/asf/commons-compress/diff/f87a7ce9 Branch: refs/heads/master Commit: f87a7ce9321b4901a77786387cfe8026f1249721 Parents: e9d6221 Author: Stefan Bodewig <bode...@apache.org> Authored: Sat Jun 11 17:27:25 2016 +0200 Committer: Stefan Bodewig <bode...@apache.org> Committed: Sat Jun 11 17:27:25 2016 +0200 ---------------------------------------------------------------------- src/changes/changes.xml | 4 ++-- .../compressors/bzip2/BZip2CompressorOutputStream.java | 12 +++++------- 2 files changed, 7 insertions(+), 9 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/commons-compress/blob/f87a7ce9/src/changes/changes.xml ---------------------------------------------------------------------- diff --git a/src/changes/changes.xml b/src/changes/changes.xml index d74fd98..eb9bb00 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -76,8 +76,8 @@ The <action> type attribute can be add,update,fix,remove. used in Apple's iWork 13 files. </action> <action issue="COMPRESS-357" type="fix" date="2016-05-26"> - A race-condition between BZip2CompressorOutputStream's finish - and finalize methods could lead to corrupted streams. + 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 http://git-wip-us.apache.org/repos/asf/commons-compress/blob/f87a7ce9/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 483d844..3bdee5a 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 @@ -322,7 +322,6 @@ public class BZip2CompressorOutputStream extends CompressorOutputStream private BlockSort blockSorter; private OutputStream out; - private volatile boolean closed; /** * Chooses a blocksize based on the given length of the data to compress. @@ -393,7 +392,7 @@ public class BZip2CompressorOutputStream extends CompressorOutputStream @Override public void write(final int b) throws IOException { - if (!closed) { + if (this.out != null) { write0(b); } else { throw new IOException("closed"); @@ -477,8 +476,8 @@ public class BZip2CompressorOutputStream extends CompressorOutputStream } - public void finish() throws IOException { - if (!closed) { + public synchronized void finish() throws IOException { + if (out != null) { try { if (this.runLength > 0) { writeRun(); @@ -487,7 +486,6 @@ public class BZip2CompressorOutputStream extends CompressorOutputStream endBlock(); endCompression(); } finally { - closed = true; this.out = null; this.data = null; this.blockSorter = null; @@ -497,7 +495,7 @@ public class BZip2CompressorOutputStream extends CompressorOutputStream @Override public void close() throws IOException { - if (!closed) { + if (out != null) { final OutputStream outShadow = this.out; finish(); outShadow.close(); @@ -627,7 +625,7 @@ public class BZip2CompressorOutputStream extends CompressorOutputStream + len + ") > buf.length(" + buf.length + ")."); } - if (closed) { + if (this.out == null) { throw new IOException("stream closed"); }