JDK 10 RFR of 8185092: Data race in FilterOutputStream.close

Claes Redestad claes.redestad at oracle.com
Thu Jul 27 19:41:44 UTC 2017


Looks good to me!

/Claes

On 2017-07-27 21:30, Brian Burkhalter wrote:
> On Jul 27, 2017, at 8:29 AM, Claes Redestad <claes.redestad at oracle.com 
> <mailto:claes.redestad at oracle.com>> wrote:
>
>>> I’ll change the patch accordingly.
>>
>> Thanks!
>
> Le voila:
>
> --- a/src/java.base/share/classes/java/io/FilterOutputStream.java
> +++ b/src/java.base/share/classes/java/io/FilterOutputStream.java
> @@ -50,7 +50,12 @@
>      /**
>       * Whether the stream is closed; implicitly initialized to false.
>       */
> -    private boolean closed;
> +    private volatile boolean closed;
> +
> +    /**
> +     * Object used to prevent a race on the 'closed' instance variable.
> +     */
> +    private final Object closeLock = new Object();
>
>
>      /**
>       * Creates an output stream filter built on top of the specified
> @@ -165,7 +170,12 @@
>          if (closed) {
>              return;
>          }
> -        closed = true;
> +        synchronized (closeLock) {
> +            if (closed) {
> +                return;
> +            }
> +            closed = true;
> +        }
>
>
>          Throwable flushException = null;
>          try {
>
> Thanks,
>
> Brian



More information about the nio-dev mailing list