提交 bccf8cd7 编写于 作者: B bpb

8185092: Data race in FilterOutputStream.close

Summary: Change boolean instance variable "closed" to an AtomicBoolean.
Reviewed-by: martin, alanb, redestad
上级 4f16688b
......@@ -50,7 +50,12 @@ public class FilterOutputStream extends OutputStream {
/**
* 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 @@ public class FilterOutputStream extends OutputStream {
if (closed) {
return;
}
closed = true;
synchronized (closeLock) {
if (closed) {
return;
}
closed = true;
}
Throwable flushException = null;
try {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册