Implement isValid for CloseableReferenceWithoutFinalizer
Summary: Since the `close()` method doesn't call through super, `mIsClosed` is never set to true, so `isValid()` will always return true for `CloseableReferenceWithoutFinalizer`. Override `isValid()` so this works correctly.
@@ -344,7 +344,7 @@ public abstract class CloseableReference<T> implements Cloneable, Closeable {
@GuardedBy("Destructor.class")
private Destructor previous;
@GuardedBy("this")
- private boolean closed;
+ private boolean destroyed;
public Destructor(
CloseableReference referent,
@@ -359,12 +359,16 @@ public abstract class CloseableReference<T> implements Cloneable, Closeable {
sHead = this;
}
+ public synchronized boolean isDestroyed() {
+ return destroyed;
+ }
+
public void destroy(boolean correctly) {
synchronized (this) {
- if (closed) {
+ if (destroyed) {
return;
}
- closed = true;
+ destroyed = true;
}
synchronized (Destructor.class) {
@@ -424,6 +428,11 @@ public abstract class CloseableReference<T> implements Cloneable, Closeable {
public void close() {
mDestructor.destroy(true);
}
+
+ @Override
+ public boolean isValid() {
+ return !mDestructor.isDestroyed();
+ }
}
private static class CloseableReferenceWithFinalizer<T> extends CloseableReference<T> {
