Skip to content

Commit ce75979

Browse files
cpovirkGoogle Java Core Libraries
authored andcommitted
Revise references to Android versions before our currently supported minimum (API Level 23).
Plus, update docs and internals of `ClosingFuture` to reflect that even Android has supported `AutoCloseable` since cl/631389672. RELNOTES=n/a PiperOrigin-RevId: 805817053
1 parent 7fc3290 commit ce75979

File tree

6 files changed

+22
-56
lines changed

6 files changed

+22
-56
lines changed

android/guava-tests/test/com/google/common/primitives/UnsignedBytesTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ private static boolean unsafeComparatorAvailable() {
226226
*
227227
* A note on exception types:
228228
*
229-
* Android API level 10 throws ExceptionInInitializerError the first time and
229+
* Android API level 23 throws ExceptionInInitializerError the first time and
230230
* ClassNotFoundException thereafter.
231231
*
232232
* Android API level 26 and JVM8 both let our Error propagate directly the first time and

android/guava/src/com/google/common/base/Stopwatch.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686
* Stopwatch.createStarted(
8787
* new Ticker() {
8888
* public long read() {
89-
* return android.os.SystemClock.elapsedRealtimeNanos(); // requires API Level 17
89+
* return android.os.SystemClock.elapsedRealtimeNanos();
9090
* }
9191
* });
9292
* }

android/guava/src/com/google/common/util/concurrent/ClosingFuture.java

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
import com.google.errorprone.annotations.CanIgnoreReturnValue;
4949
import com.google.errorprone.annotations.DoNotMock;
5050
import com.google.j2objc.annotations.RetainedWith;
51-
import java.io.Closeable;
5251
import java.util.IdentityHashMap;
5352
import java.util.Map;
5453
import java.util.concurrent.Callable;
@@ -210,23 +209,15 @@ public static final class DeferredCloser {
210209
/**
211210
* Captures an object to be closed when a {@link ClosingFuture} pipeline is done.
212211
*
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-
*
219212
* <p>Be careful when targeting an older SDK than you are building against (most commonly when
220213
* building for Android): Ensure that any object you pass implements the interface not just in
221214
* 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}.
228219
*
229-
* @param closeable the object to be closed (see notes above)
220+
* @param closeable the object to be closed
230221
* @param closingExecutor the object will be closed on this executor
231222
* @return the first argument
232223
*/
@@ -440,7 +431,7 @@ public String toString() {
440431
* Starts a {@link ClosingFuture} pipeline with a {@link ListenableFuture}.
441432
*
442433
* <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
444435
* when the pipeline is done, use {@link #submit(ClosingCallable, Executor)} instead.
445436
*/
446437
public static <V extends @Nullable Object> ClosingFuture<V> from(ListenableFuture<V> future) {
@@ -741,7 +732,7 @@ public String toString() {
741732
*
742733
* // Result.writeRowsToOutputStreamFuture() returns a ListenableFuture that resolves to the
743734
* // number of written rows. openOutputFile() returns a FileOutputStream (which implements
744-
* // Closeable).
735+
* // AutoCloseable).
745736
* ClosingFuture<Integer> rowsFuture2 =
746737
* queryFuture.transformAsync(
747738
* (closer, result) -> {
@@ -803,7 +794,7 @@ public String toString() {
803794
* meets these conditions:
804795
*
805796
* <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
807798
* DeferredCloser#eventuallyClose(Object, Executor)}.
808799
* <li>It returns a {@link ListenableFuture}.
809800
* </ul>
@@ -2121,14 +2112,6 @@ private static void closeQuietly(@Nullable AutoCloseable closeable, Executor exe
21212112
try {
21222113
closeable.close();
21232114
} 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-
*/
21322115
restoreInterruptIfIsInterruptedException(e);
21332116
logger.get().log(WARNING, "thrown by close()", e);
21342117
}
@@ -2160,7 +2143,7 @@ private boolean compareAndUpdateState(State oldState, State newState) {
21602143

21612144
// TODO(dpb): Should we use a pair of ArrayLists instead of an IdentityHashMap?
21622145
private static final class CloseableList extends IdentityHashMap<AutoCloseable, Executor>
2163-
implements Closeable {
2146+
implements AutoCloseable {
21642147
private final DeferredCloser closer = new DeferredCloser(this);
21652148
private volatile boolean closed;
21662149
private volatile @Nullable CountDownLatch whenClosed;

guava-tests/test/com/google/common/primitives/UnsignedBytesTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ private static boolean unsafeComparatorAvailable() {
227227
*
228228
* A note on exception types:
229229
*
230-
* Android API level 10 throws ExceptionInInitializerError the first time and
230+
* Android API level 23 throws ExceptionInInitializerError the first time and
231231
* ClassNotFoundException thereafter.
232232
*
233233
* Android API level 26 and JVM8 both let our Error propagate directly the first time and

guava/src/com/google/common/base/Stopwatch.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686
* Stopwatch.createStarted(
8787
* new Ticker() {
8888
* public long read() {
89-
* return android.os.SystemClock.elapsedRealtimeNanos(); // requires API Level 17
89+
* return android.os.SystemClock.elapsedRealtimeNanos();
9090
* }
9191
* });
9292
* }

guava/src/com/google/common/util/concurrent/ClosingFuture.java

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
import com.google.errorprone.annotations.CanIgnoreReturnValue;
4949
import com.google.errorprone.annotations.DoNotMock;
5050
import com.google.j2objc.annotations.RetainedWith;
51-
import java.io.Closeable;
5251
import java.util.IdentityHashMap;
5352
import java.util.Map;
5453
import java.util.concurrent.Callable;
@@ -210,23 +209,15 @@ public static final class DeferredCloser {
210209
/**
211210
* Captures an object to be closed when a {@link ClosingFuture} pipeline is done.
212211
*
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-
*
219212
* <p>Be careful when targeting an older SDK than you are building against (most commonly when
220213
* building for Android): Ensure that any object you pass implements the interface not just in
221214
* 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}.
228219
*
229-
* @param closeable the object to be closed (see notes above)
220+
* @param closeable the object to be closed
230221
* @param closingExecutor the object will be closed on this executor
231222
* @return the first argument
232223
*/
@@ -445,7 +436,7 @@ public String toString() {
445436
* Starts a {@link ClosingFuture} pipeline with a {@link ListenableFuture}.
446437
*
447438
* <p>{@code future}'s value will not be closed when the pipeline is done even if {@code V}
448-
* implements {@link Closeable}. In order to start a pipeline with a value that will be closed
439+
* implements {@link AutoCloseable}. In order to start a pipeline with a value that will be closed
449440
* when the pipeline is done, use {@link #submit(ClosingCallable, Executor)} instead.
450441
*/
451442
public static <V extends @Nullable Object> ClosingFuture<V> from(ListenableFuture<V> future) {
@@ -746,7 +737,7 @@ public String toString() {
746737
*
747738
* // Result.writeRowsToOutputStreamFuture() returns a ListenableFuture that resolves to the
748739
* // number of written rows. openOutputFile() returns a FileOutputStream (which implements
749-
* // Closeable).
740+
* // AutoCloseable).
750741
* ClosingFuture<Integer> rowsFuture2 =
751742
* queryFuture.transformAsync(
752743
* (closer, result) -> {
@@ -808,7 +799,7 @@ public String toString() {
808799
* meets these conditions:
809800
*
810801
* <ul>
811-
* <li>It does not need to capture any {@link Closeable} objects by calling {@link
802+
* <li>It does not need to capture any {@link AutoCloseable} objects by calling {@link
812803
* DeferredCloser#eventuallyClose(Object, Executor)}.
813804
* <li>It returns a {@link ListenableFuture}.
814805
* </ul>
@@ -2136,14 +2127,6 @@ private static void closeQuietly(@Nullable AutoCloseable closeable, Executor exe
21362127
try {
21372128
closeable.close();
21382129
} catch (Exception e) {
2139-
/*
2140-
* In guava-jre, any kind of Exception may be thrown because `closeable` has type
2141-
* `AutoCloseable`.
2142-
*
2143-
* In guava-android, the only kinds of Exception that may be thrown are
2144-
* RuntimeException and IOException because `closeable` has type `Closeable`—except
2145-
* that we have to account for sneaky checked exception.
2146-
*/
21472130
restoreInterruptIfIsInterruptedException(e);
21482131
logger.get().log(WARNING, "thrown by close()", e);
21492132
}
@@ -2175,7 +2158,7 @@ private boolean compareAndUpdateState(State oldState, State newState) {
21752158

21762159
// TODO(dpb): Should we use a pair of ArrayLists instead of an IdentityHashMap?
21772160
private static final class CloseableList extends IdentityHashMap<AutoCloseable, Executor>
2178-
implements Closeable {
2161+
implements AutoCloseable {
21792162
private final DeferredCloser closer = new DeferredCloser(this);
21802163
private volatile boolean closed;
21812164
private volatile @Nullable CountDownLatch whenClosed;

0 commit comments

Comments
 (0)