commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sebb <seb...@gmail.com>
Subject Re: commons-compress git commit: better set that flag earlier
Date Fri, 10 Jun 2016 14:18:28 GMT
On 10 June 2016 at 14:01,  <bodewig@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 <bodewig@apache.org>
> Authored: Fri Jun 10 15:00:53 2016 +0200
> Committer: Stefan Bodewig <bodewig@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-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Mime
View raw message