JDK 10 RFR of 8185092: Data race in FilterOutputStream.close
Alan Bateman
Alan.Bateman at oracle.com
Thu Jul 27 11:05:36 UTC 2017
On 26/07/2017 18:52, Brian Burkhalter wrote:
> :
>
> --- a/src/java.base/share/classes/java/io/FilterOutputStream.java
> +++ b/src/java.base/share/classes/java/io/FilterOutputStream.java
> @@ -25,6 +25,8 @@
>
> package java.io;
>
> +import java.util.concurrent.atomic.AtomicBoolean;
> +
> /**
> * This class is the superclass of all classes that filter output
> * streams. These streams sit on top of an already existing output
> @@ -50,7 +52,7 @@
> /**
> * Whether the stream is closed; implicitly initialized to false.
> */
> - private boolean closed;
> + private AtomicBoolean closed = new AtomicBoolean();
>
> /**
> * Creates an output stream filter built on top of the specified
> @@ -162,10 +164,9 @@
> */
> @Override
> public void close() throws IOException {
> - if (closed) {
> + if (closed.getAndSet(true)) {
> return;
> }
> - closed = true;
>
> Throwable flushException = null;
> try {
This is probably okay but would be good to check the impact on startup
(as FileOutputStream is loaded early as part of initializing System.out
and err).
-Alan
More information about the nio-dev
mailing list