COMPRESS-357 synchronize the important part of finish again
Project: http://git-wip-us.apache.org/repos/asf/commons-compress/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-compress/commit/abc2d239 Tree: http://git-wip-us.apache.org/repos/asf/commons-compress/tree/abc2d239 Diff: http://git-wip-us.apache.org/repos/asf/commons-compress/diff/abc2d239 Branch: refs/heads/master Commit: abc2d23900ff5adeef648879af6bc4d2f79c261e Parents: f87a7ce Author: Stefan Bodewig <bode...@apache.org> Authored: Sat Jun 11 17:33:15 2016 +0200 Committer: Stefan Bodewig <bode...@apache.org> Committed: Sat Jun 11 17:33:15 2016 +0200 ---------------------------------------------------------------------- .../bzip2/BZip2CompressorOutputStream.java | 27 +++++++++++--------- 1 file changed, 15 insertions(+), 12 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/commons-compress/blob/abc2d239/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 3bdee5a..034fbfc 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,6 +321,7 @@ public class BZip2CompressorOutputStream extends CompressorOutputStream private Data data; private BlockSort blockSorter; + private final Object outLock = new Object(); private OutputStream out; /** @@ -476,21 +477,23 @@ public class BZip2CompressorOutputStream extends CompressorOutputStream } - public synchronized void finish() throws IOException { - if (out != null) { - try { - if (this.runLength > 0) { - writeRun(); + 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; } - this.currentChar = -1; - endBlock(); - endCompression(); - } finally { - this.out = null; - this.data = null; - this.blockSorter = null; } } + this.blockSorter = null; + this.data = null; } @Override