JDK 10 RFR of 8185092: Data race in FilterOutputStream.close
Brian Burkhalter
brian.burkhalter at oracle.com
Thu Jul 27 19:30:45 UTC 2017
On Jul 27, 2017, at 8:29 AM, Claes Redestad <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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/nio-dev/attachments/20170727/2db84551/attachment.html>
More information about the nio-dev
mailing list