On 10 June 2016 at 14:01, <bode...@apache.org> wrote: > Repository: commons-compress > Updated Branches: > refs/heads/master 8769bb698 -> bdc5ad445 > > > better set that flag earlier
Surely if it matters when the flag is set, then it also matters that there is still a window between checking the flag and setting it? As it stands, if the finish method can be called from two threads then both can end up writing the trailer. Isn't that why the code was synch in the first place? Maybe try: AtomicBoolean closed = new AtomicBoolean(false); if (!closed.getAndSet(true)) { } > > Project: http://git-wip-us.apache.org/repos/asf/commons-compress/repo > Commit: > http://git-wip-us.apache.org/repos/asf/commons-compress/commit/bdc5ad44 > Tree: http://git-wip-us.apache.org/repos/asf/commons-compress/tree/bdc5ad44 > Diff: http://git-wip-us.apache.org/repos/asf/commons-compress/diff/bdc5ad44 > > Branch: refs/heads/master > Commit: bdc5ad445101133b7c92f4b2efbad1993913e160 > Parents: 8769bb6 > Author: Stefan Bodewig <bode...@apache.org> > Authored: Fri Jun 10 15:00:53 2016 +0200 > Committer: Stefan Bodewig <bode...@apache.org> > Committed: Fri Jun 10 15:00:53 2016 +0200 > > ---------------------------------------------------------------------- > .../compress/compressors/bzip2/BZip2CompressorOutputStream.java | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > ---------------------------------------------------------------------- > > > http://git-wip-us.apache.org/repos/asf/commons-compress/blob/bdc5ad44/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..8cc6c39 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 > @@ -479,6 +479,7 @@ public class BZip2CompressorOutputStream extends > CompressorOutputStream > > public void finish() throws IOException { > if (!closed) { > + closed = true; > try { > if (this.runLength > 0) { > writeRun(); > @@ -487,7 +488,6 @@ public class BZip2CompressorOutputStream extends > CompressorOutputStream > endBlock(); > endCompression(); > } finally { > - closed = true; > this.out = null; > this.data = null; > this.blockSorter = null; > --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org For additional commands, e-mail: dev-h...@commons.apache.org