|
48 | 48 | import com.google.errorprone.annotations.CanIgnoreReturnValue;
|
49 | 49 | import com.google.errorprone.annotations.DoNotMock;
|
50 | 50 | import com.google.j2objc.annotations.RetainedWith;
|
51 |
| -import java.io.Closeable; |
52 | 51 | import java.util.IdentityHashMap;
|
53 | 52 | import java.util.Map;
|
54 | 53 | import java.util.concurrent.Callable;
|
@@ -210,23 +209,15 @@ public static final class DeferredCloser {
|
210 | 209 | /**
|
211 | 210 | * Captures an object to be closed when a {@link ClosingFuture} pipeline is done.
|
212 | 211 | *
|
213 |
| - * <p>For users of the {@code -jre} flavor of Guava, the object can be any {@code |
214 |
| - * AutoCloseable}. For users of the {@code -android} flavor, the object must be a {@code |
215 |
| - * Closeable}. (For more about the flavors, see <a |
216 |
| - * href="https://github.com/google/guava#adding-guava-to-your-build">Adding Guava to your |
217 |
| - * build</a>.) |
218 |
| - * |
219 | 212 | * <p>Be careful when targeting an older SDK than you are building against (most commonly when
|
220 | 213 | * building for Android): Ensure that any object you pass implements the interface not just in
|
221 | 214 | * your current SDK version but also at the oldest version you support. For example, <a
|
222 |
| - * href="https://developer.android.com/sdk/api_diff/16/">API Level 16</a> is the first version |
223 |
| - * in which {@code Cursor} is {@code Closeable}. To support older versions, pass a wrapper |
224 |
| - * {@code Closeable} with a method reference like {@code cursor::close}. |
225 |
| - * |
226 |
| - * <p>Note that this method is still binary-compatible between flavors because the erasure of |
227 |
| - * its parameter type is {@code Object}, not {@code AutoCloseable} or {@code Closeable}. |
| 215 | + * href="https://developer.android.com/sdk/api_diff/28/changes/android.media.MediaDrm#android.media.MediaDrm.close_added()">API |
| 216 | + * Level 28</a> is the first version in which {@code MediaDrm} is {@code AutoCloseable}. To |
| 217 | + * support older versions, pass a wrapper {@code AutoCloseable} with a method reference like |
| 218 | + * {@code mediaDrm::release}. |
228 | 219 | *
|
229 |
| - * @param closeable the object to be closed (see notes above) |
| 220 | + * @param closeable the object to be closed |
230 | 221 | * @param closingExecutor the object will be closed on this executor
|
231 | 222 | * @return the first argument
|
232 | 223 | */
|
@@ -440,7 +431,7 @@ public String toString() {
|
440 | 431 | * Starts a {@link ClosingFuture} pipeline with a {@link ListenableFuture}.
|
441 | 432 | *
|
442 | 433 | * <p>{@code future}'s value will not be closed when the pipeline is done even if {@code V}
|
443 |
| - * implements {@link Closeable}. In order to start a pipeline with a value that will be closed |
| 434 | + * implements {@link AutoCloseable}. In order to start a pipeline with a value that will be closed |
444 | 435 | * when the pipeline is done, use {@link #submit(ClosingCallable, Executor)} instead.
|
445 | 436 | */
|
446 | 437 | public static <V extends @Nullable Object> ClosingFuture<V> from(ListenableFuture<V> future) {
|
@@ -741,7 +732,7 @@ public String toString() {
|
741 | 732 | *
|
742 | 733 | * // Result.writeRowsToOutputStreamFuture() returns a ListenableFuture that resolves to the
|
743 | 734 | * // number of written rows. openOutputFile() returns a FileOutputStream (which implements
|
744 |
| - * // Closeable). |
| 735 | + * // AutoCloseable). |
745 | 736 | * ClosingFuture<Integer> rowsFuture2 =
|
746 | 737 | * queryFuture.transformAsync(
|
747 | 738 | * (closer, result) -> {
|
@@ -803,7 +794,7 @@ public String toString() {
|
803 | 794 | * meets these conditions:
|
804 | 795 | *
|
805 | 796 | * <ul>
|
806 |
| - * <li>It does not need to capture any {@link Closeable} objects by calling {@link |
| 797 | + * <li>It does not need to capture any {@link AutoCloseable} objects by calling {@link |
807 | 798 | * DeferredCloser#eventuallyClose(Object, Executor)}.
|
808 | 799 | * <li>It returns a {@link ListenableFuture}.
|
809 | 800 | * </ul>
|
@@ -2121,14 +2112,6 @@ private static void closeQuietly(@Nullable AutoCloseable closeable, Executor exe
|
2121 | 2112 | try {
|
2122 | 2113 | closeable.close();
|
2123 | 2114 | } catch (Exception e) {
|
2124 |
| - /* |
2125 |
| - * In guava-jre, any kind of Exception may be thrown because `closeable` has type |
2126 |
| - * `AutoCloseable`. |
2127 |
| - * |
2128 |
| - * In guava-android, the only kinds of Exception that may be thrown are |
2129 |
| - * RuntimeException and IOException because `closeable` has type `Closeable`—except |
2130 |
| - * that we have to account for sneaky checked exception. |
2131 |
| - */ |
2132 | 2115 | restoreInterruptIfIsInterruptedException(e);
|
2133 | 2116 | logger.get().log(WARNING, "thrown by close()", e);
|
2134 | 2117 | }
|
@@ -2160,7 +2143,7 @@ private boolean compareAndUpdateState(State oldState, State newState) {
|
2160 | 2143 |
|
2161 | 2144 | // TODO(dpb): Should we use a pair of ArrayLists instead of an IdentityHashMap?
|
2162 | 2145 | private static final class CloseableList extends IdentityHashMap<AutoCloseable, Executor>
|
2163 |
| - implements Closeable { |
| 2146 | + implements AutoCloseable { |
2164 | 2147 | private final DeferredCloser closer = new DeferredCloser(this);
|
2165 | 2148 | private volatile boolean closed;
|
2166 | 2149 | private volatile @Nullable CountDownLatch whenClosed;
|
|
0 commit comments