Skip to content

Commit d3232b7

Browse files
java-team-github-botGoogle Java Core Libraries
authored andcommitted
Move tsan suppressions to annotations
RELNOTES=Improved j2objc compatibility PiperOrigin-RevId: 603470054
1 parent a9d243c commit d3232b7

18 files changed

+56
-32
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import com.google.common.util.concurrent.internal.InternalFutureFailureAccess;
2727
import com.google.common.util.concurrent.internal.InternalFutures;
2828
import com.google.errorprone.annotations.ForOverride;
29+
import com.google.errorprone.annotations.concurrent.LazyInit;
2930
import java.util.concurrent.ExecutionException;
3031
import java.util.concurrent.Executor;
3132
import javax.annotation.CheckForNull;
@@ -62,9 +63,9 @@ abstract class AbstractCatchingFuture<
6263
* In certain circumstances, this field might theoretically not be visible to an afterDone() call
6364
* triggered by cancel(). For details, see the comments on the fields of TimeoutFuture.
6465
*/
65-
@CheckForNull ListenableFuture<? extends V> inputFuture;
66-
@CheckForNull Class<X> exceptionType;
67-
@CheckForNull F fallback;
66+
@CheckForNull @LazyInit ListenableFuture<? extends V> inputFuture;
67+
@CheckForNull @LazyInit Class<X> exceptionType;
68+
@CheckForNull @LazyInit F fallback;
6869

6970
AbstractCatchingFuture(
7071
ListenableFuture<? extends V> inputFuture, Class<X> exceptionType, F fallback) {

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import com.google.common.annotations.GwtCompatible;
2323
import com.google.common.base.Function;
2424
import com.google.errorprone.annotations.ForOverride;
25+
import com.google.errorprone.annotations.concurrent.LazyInit;
2526
import java.util.concurrent.CancellationException;
2627
import java.util.concurrent.ExecutionException;
2728
import java.util.concurrent.Executor;
@@ -57,8 +58,8 @@ abstract class AbstractTransformFuture<
5758
* In certain circumstances, this field might theoretically not be visible to an afterDone() call
5859
* triggered by cancel(). For details, see the comments on the fields of TimeoutFuture.
5960
*/
60-
@CheckForNull ListenableFuture<? extends I> inputFuture;
61-
@CheckForNull F function;
61+
@CheckForNull @LazyInit ListenableFuture<? extends I> inputFuture;
62+
@CheckForNull @LazyInit F function;
6263

6364
AbstractTransformFuture(ListenableFuture<? extends I> inputFuture, F function) {
6465
this.inputFuture = checkNotNull(inputFuture);

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import com.google.common.collect.ImmutableCollection;
2828
import com.google.errorprone.annotations.ForOverride;
2929
import com.google.errorprone.annotations.OverridingMethodsMustInvokeSuper;
30+
import com.google.errorprone.annotations.concurrent.LazyInit;
3031
import java.util.Set;
3132
import java.util.concurrent.ExecutionException;
3233
import java.util.concurrent.Future;
@@ -55,7 +56,8 @@ abstract class AggregateFuture<InputT extends @Nullable Object, OutputT extends
5556
* In certain circumstances, this field might theoretically not be visible to an afterDone() call
5657
* triggered by cancel(). For details, see the comments on the fields of TimeoutFuture.
5758
*/
58-
@CheckForNull private ImmutableCollection<? extends ListenableFuture<? extends InputT>> futures;
59+
@CheckForNull @LazyInit
60+
private ImmutableCollection<? extends ListenableFuture<? extends InputT>> futures;
5961

6062
private final boolean allMustSucceed;
6163
private final boolean collectsValues;

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import com.google.common.annotations.GwtCompatible;
2121
import com.google.common.collect.ImmutableCollection;
2222
import com.google.common.collect.Lists;
23+
import com.google.errorprone.annotations.concurrent.LazyInit;
2324
import java.util.Collections;
2425
import java.util.List;
2526
import javax.annotation.CheckForNull;
@@ -36,7 +37,7 @@ abstract class CollectionFuture<V extends @Nullable Object, C extends @Nullable
3637
* there: cancel() never reads this field, only writes to it. That makes the race here completely
3738
* harmless, rather than just 99.99% harmless.
3839
*/
39-
@CheckForNull private List<@Nullable Present<V>> values;
40+
@CheckForNull @LazyInit private List<@Nullable Present<V>> values;
4041

4142
CollectionFuture(
4243
ImmutableCollection<? extends ListenableFuture<? extends V>> futures,

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import com.google.common.annotations.GwtCompatible;
2121
import com.google.common.collect.ImmutableCollection;
22+
import com.google.errorprone.annotations.concurrent.LazyInit;
2223
import com.google.j2objc.annotations.WeakOuter;
2324
import java.util.concurrent.Callable;
2425
import java.util.concurrent.CancellationException;
@@ -33,7 +34,7 @@
3334
@ElementTypesAreNonnullByDefault
3435
final class CombinedFuture<V extends @Nullable Object>
3536
extends AggregateFuture<@Nullable Object, V> {
36-
@CheckForNull private CombinedFutureInterruptibleTask<?> task;
37+
@CheckForNull @LazyInit private CombinedFutureInterruptibleTask<?> task;
3738

3839
CombinedFuture(
3940
ImmutableCollection<? extends ListenableFuture<?>> futures,

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@
2626
import static java.util.Objects.requireNonNull;
2727

2828
import com.google.common.annotations.J2ktIncompatible;
29+
import com.google.errorprone.annotations.concurrent.LazyInit;
2930
import java.util.concurrent.Callable;
3031
import java.util.concurrent.Executor;
31-
import java.util.concurrent.Future;
3232
import java.util.concurrent.atomic.AtomicReference;
3333
import javax.annotation.CheckForNull;
3434
import org.checkerframework.checker.nullness.qual.Nullable;
@@ -100,7 +100,7 @@ public static ExecutionSequencer create() {
100100
private final AtomicReference<ListenableFuture<@Nullable Void>> ref =
101101
new AtomicReference<>(immediateVoidFuture());
102102

103-
private ThreadConfinedTaskQueue latestTaskQueue = new ThreadConfinedTaskQueue();
103+
private @LazyInit ThreadConfinedTaskQueue latestTaskQueue = new ThreadConfinedTaskQueue();
104104

105105
/**
106106
* This object is unsafely published, but avoids problematic races by relying exclusively on the
@@ -131,9 +131,11 @@ private static final class ThreadConfinedTaskQueue {
131131
* All the states where thread != currentThread are identical for our purposes, and so even
132132
* though it's racy, we don't care which of those values we get, so no need to synchronize.
133133
*/
134-
@CheckForNull Thread thread;
134+
@CheckForNull @LazyInit Thread thread;
135+
135136
/** Only used by the thread associated with this object */
136137
@CheckForNull Runnable nextTask;
138+
137139
/** Only used by the thread associated with this object */
138140
@CheckForNull Executor nextExecutor;
139141
}
@@ -308,7 +310,7 @@ private static final class TaskNonReentrantExecutor extends AtomicReference<Runn
308310
@CheckForNull Runnable task;
309311

310312
/** Thread that called execute(). Set in execute, cleared when delegate.execute() returns. */
311-
@CheckForNull Thread submitting;
313+
@CheckForNull @LazyInit Thread submitting;
312314

313315
private TaskNonReentrantExecutor(Executor delegate, ExecutionSequencer sequencer) {
314316
super(NOT_RUN);

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import com.google.common.util.concurrent.internal.InternalFutureFailureAccess;
3434
import com.google.common.util.concurrent.internal.InternalFutures;
3535
import com.google.errorprone.annotations.CanIgnoreReturnValue;
36+
import com.google.errorprone.annotations.concurrent.LazyInit;
3637
import java.util.Collection;
3738
import java.util.List;
3839
import java.util.concurrent.Callable;
@@ -760,7 +761,7 @@ public Void call() throws Exception {
760761
/** A wrapped future that does not propagate cancellation to its delegate. */
761762
private static final class NonCancellationPropagatingFuture<V extends @Nullable Object>
762763
extends AbstractFuture.TrustedFuture<V> implements Runnable {
763-
@CheckForNull private ListenableFuture<V> delegate;
764+
@CheckForNull @LazyInit private ListenableFuture<V> delegate;
764765

765766
NonCancellationPropagatingFuture(final ListenableFuture<V> delegate) {
766767
this.delegate = delegate;

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import com.google.common.annotations.J2ktIncompatible;
2626
import com.google.common.base.Preconditions;
2727
import com.google.errorprone.annotations.concurrent.GuardedBy;
28+
import com.google.errorprone.annotations.concurrent.LazyInit;
2829
import com.google.j2objc.annotations.RetainedWith;
2930
import java.util.ArrayDeque;
3031
import java.util.Deque;
@@ -70,6 +71,7 @@ enum WorkerRunningState {
7071
private final Deque<Runnable> queue = new ArrayDeque<>();
7172

7273
/** see {@link WorkerRunningState} */
74+
@LazyInit
7375
@GuardedBy("queue")
7476
private WorkerRunningState workerRunningState = IDLE;
7577

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import com.google.common.annotations.GwtIncompatible;
2020
import com.google.common.annotations.J2ktIncompatible;
2121
import com.google.common.base.Preconditions;
22+
import com.google.errorprone.annotations.concurrent.LazyInit;
2223
import java.util.concurrent.ExecutionException;
2324
import java.util.concurrent.Future;
2425
import java.util.concurrent.ScheduledExecutorService;
@@ -75,16 +76,16 @@ final class TimeoutFuture<V extends @Nullable Object> extends FluentFuture.Trust
7576
* write-barriers).
7677
*/
7778

78-
@CheckForNull private ListenableFuture<V> delegateRef;
79-
@CheckForNull private ScheduledFuture<?> timer;
79+
@CheckForNull @LazyInit private ListenableFuture<V> delegateRef;
80+
@CheckForNull @LazyInit private ScheduledFuture<?> timer;
8081

8182
private TimeoutFuture(ListenableFuture<V> delegate) {
8283
this.delegateRef = Preconditions.checkNotNull(delegate);
8384
}
8485

8586
/** A runnable that is called when the delegate or the timer completes. */
8687
private static final class Fire<V extends @Nullable Object> implements Runnable {
87-
@CheckForNull TimeoutFuture<V> timeoutFutureRef;
88+
@CheckForNull @LazyInit TimeoutFuture<V> timeoutFutureRef;
8889

8990
Fire(TimeoutFuture<V> timeoutFuture) {
9091
this.timeoutFutureRef = timeoutFuture;

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import com.google.common.util.concurrent.internal.InternalFutureFailureAccess;
2727
import com.google.common.util.concurrent.internal.InternalFutures;
2828
import com.google.errorprone.annotations.ForOverride;
29+
import com.google.errorprone.annotations.concurrent.LazyInit;
2930
import java.util.concurrent.ExecutionException;
3031
import java.util.concurrent.Executor;
3132
import javax.annotation.CheckForNull;
@@ -62,9 +63,9 @@ abstract class AbstractCatchingFuture<
6263
* In certain circumstances, this field might theoretically not be visible to an afterDone() call
6364
* triggered by cancel(). For details, see the comments on the fields of TimeoutFuture.
6465
*/
65-
@CheckForNull ListenableFuture<? extends V> inputFuture;
66-
@CheckForNull Class<X> exceptionType;
67-
@CheckForNull F fallback;
66+
@CheckForNull @LazyInit ListenableFuture<? extends V> inputFuture;
67+
@CheckForNull @LazyInit Class<X> exceptionType;
68+
@CheckForNull @LazyInit F fallback;
6869

6970
AbstractCatchingFuture(
7071
ListenableFuture<? extends V> inputFuture, Class<X> exceptionType, F fallback) {

0 commit comments

Comments
 (0)