From d3232b71ce5eee2fb861a7f75bcebe1290afafdc Mon Sep 17 00:00:00 2001 From: Google Java Core Libraries Date: Thu, 1 Feb 2024 13:43:05 -0800 Subject: [PATCH] Move tsan suppressions to annotations RELNOTES=Improved j2objc compatibility PiperOrigin-RevId: 603470054 --- .../common/util/concurrent/AbstractCatchingFuture.java | 7 ++++--- .../util/concurrent/AbstractTransformFuture.java | 5 +++-- .../google/common/util/concurrent/AggregateFuture.java | 4 +++- .../common/util/concurrent/CollectionFuture.java | 3 ++- .../google/common/util/concurrent/CombinedFuture.java | 3 ++- .../common/util/concurrent/ExecutionSequencer.java | 10 ++++++---- .../src/com/google/common/util/concurrent/Futures.java | 3 ++- .../common/util/concurrent/SequentialExecutor.java | 2 ++ .../google/common/util/concurrent/TimeoutFuture.java | 7 ++++--- .../common/util/concurrent/AbstractCatchingFuture.java | 7 ++++--- .../util/concurrent/AbstractTransformFuture.java | 5 +++-- .../google/common/util/concurrent/AggregateFuture.java | 4 +++- .../common/util/concurrent/CollectionFuture.java | 3 ++- .../google/common/util/concurrent/CombinedFuture.java | 3 ++- .../common/util/concurrent/ExecutionSequencer.java | 10 ++++++---- .../src/com/google/common/util/concurrent/Futures.java | 3 ++- .../common/util/concurrent/SequentialExecutor.java | 2 ++ .../google/common/util/concurrent/TimeoutFuture.java | 7 ++++--- 18 files changed, 56 insertions(+), 32 deletions(-) diff --git a/android/guava/src/com/google/common/util/concurrent/AbstractCatchingFuture.java b/android/guava/src/com/google/common/util/concurrent/AbstractCatchingFuture.java index 8fa6500280d6..6555872a9744 100644 --- a/android/guava/src/com/google/common/util/concurrent/AbstractCatchingFuture.java +++ b/android/guava/src/com/google/common/util/concurrent/AbstractCatchingFuture.java @@ -26,6 +26,7 @@ import com.google.common.util.concurrent.internal.InternalFutureFailureAccess; import com.google.common.util.concurrent.internal.InternalFutures; import com.google.errorprone.annotations.ForOverride; +import com.google.errorprone.annotations.concurrent.LazyInit; import java.util.concurrent.ExecutionException; import java.util.concurrent.Executor; import javax.annotation.CheckForNull; @@ -62,9 +63,9 @@ abstract class AbstractCatchingFuture< * In certain circumstances, this field might theoretically not be visible to an afterDone() call * triggered by cancel(). For details, see the comments on the fields of TimeoutFuture. */ - @CheckForNull ListenableFuture inputFuture; - @CheckForNull Class exceptionType; - @CheckForNull F fallback; + @CheckForNull @LazyInit ListenableFuture inputFuture; + @CheckForNull @LazyInit Class exceptionType; + @CheckForNull @LazyInit F fallback; AbstractCatchingFuture( ListenableFuture inputFuture, Class exceptionType, F fallback) { diff --git a/android/guava/src/com/google/common/util/concurrent/AbstractTransformFuture.java b/android/guava/src/com/google/common/util/concurrent/AbstractTransformFuture.java index 3c5f30b63fb9..f23333c5dc1c 100644 --- a/android/guava/src/com/google/common/util/concurrent/AbstractTransformFuture.java +++ b/android/guava/src/com/google/common/util/concurrent/AbstractTransformFuture.java @@ -22,6 +22,7 @@ import com.google.common.annotations.GwtCompatible; import com.google.common.base.Function; import com.google.errorprone.annotations.ForOverride; +import com.google.errorprone.annotations.concurrent.LazyInit; import java.util.concurrent.CancellationException; import java.util.concurrent.ExecutionException; import java.util.concurrent.Executor; @@ -57,8 +58,8 @@ abstract class AbstractTransformFuture< * In certain circumstances, this field might theoretically not be visible to an afterDone() call * triggered by cancel(). For details, see the comments on the fields of TimeoutFuture. */ - @CheckForNull ListenableFuture inputFuture; - @CheckForNull F function; + @CheckForNull @LazyInit ListenableFuture inputFuture; + @CheckForNull @LazyInit F function; AbstractTransformFuture(ListenableFuture inputFuture, F function) { this.inputFuture = checkNotNull(inputFuture); diff --git a/android/guava/src/com/google/common/util/concurrent/AggregateFuture.java b/android/guava/src/com/google/common/util/concurrent/AggregateFuture.java index 35347741667d..a29430dee100 100644 --- a/android/guava/src/com/google/common/util/concurrent/AggregateFuture.java +++ b/android/guava/src/com/google/common/util/concurrent/AggregateFuture.java @@ -27,6 +27,7 @@ import com.google.common.collect.ImmutableCollection; import com.google.errorprone.annotations.ForOverride; import com.google.errorprone.annotations.OverridingMethodsMustInvokeSuper; +import com.google.errorprone.annotations.concurrent.LazyInit; import java.util.Set; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; @@ -55,7 +56,8 @@ abstract class AggregateFuture> futures; + @CheckForNull @LazyInit + private ImmutableCollection> futures; private final boolean allMustSucceed; private final boolean collectsValues; diff --git a/android/guava/src/com/google/common/util/concurrent/CollectionFuture.java b/android/guava/src/com/google/common/util/concurrent/CollectionFuture.java index 062aee7a79dc..445f6ccac305 100644 --- a/android/guava/src/com/google/common/util/concurrent/CollectionFuture.java +++ b/android/guava/src/com/google/common/util/concurrent/CollectionFuture.java @@ -20,6 +20,7 @@ import com.google.common.annotations.GwtCompatible; import com.google.common.collect.ImmutableCollection; import com.google.common.collect.Lists; +import com.google.errorprone.annotations.concurrent.LazyInit; import java.util.Collections; import java.util.List; import javax.annotation.CheckForNull; @@ -36,7 +37,7 @@ abstract class CollectionFuture> values; + @CheckForNull @LazyInit private List<@Nullable Present> values; CollectionFuture( ImmutableCollection> futures, diff --git a/android/guava/src/com/google/common/util/concurrent/CombinedFuture.java b/android/guava/src/com/google/common/util/concurrent/CombinedFuture.java index c22211164c40..fbbf113fa8be 100644 --- a/android/guava/src/com/google/common/util/concurrent/CombinedFuture.java +++ b/android/guava/src/com/google/common/util/concurrent/CombinedFuture.java @@ -19,6 +19,7 @@ import com.google.common.annotations.GwtCompatible; import com.google.common.collect.ImmutableCollection; +import com.google.errorprone.annotations.concurrent.LazyInit; import com.google.j2objc.annotations.WeakOuter; import java.util.concurrent.Callable; import java.util.concurrent.CancellationException; @@ -33,7 +34,7 @@ @ElementTypesAreNonnullByDefault final class CombinedFuture extends AggregateFuture<@Nullable Object, V> { - @CheckForNull private CombinedFutureInterruptibleTask task; + @CheckForNull @LazyInit private CombinedFutureInterruptibleTask task; CombinedFuture( ImmutableCollection> futures, diff --git a/android/guava/src/com/google/common/util/concurrent/ExecutionSequencer.java b/android/guava/src/com/google/common/util/concurrent/ExecutionSequencer.java index c335711c064f..4e13a9d0b315 100644 --- a/android/guava/src/com/google/common/util/concurrent/ExecutionSequencer.java +++ b/android/guava/src/com/google/common/util/concurrent/ExecutionSequencer.java @@ -26,9 +26,9 @@ import static java.util.Objects.requireNonNull; import com.google.common.annotations.J2ktIncompatible; +import com.google.errorprone.annotations.concurrent.LazyInit; import java.util.concurrent.Callable; import java.util.concurrent.Executor; -import java.util.concurrent.Future; import java.util.concurrent.atomic.AtomicReference; import javax.annotation.CheckForNull; import org.checkerframework.checker.nullness.qual.Nullable; @@ -100,7 +100,7 @@ public static ExecutionSequencer create() { private final AtomicReference> ref = new AtomicReference<>(immediateVoidFuture()); - private ThreadConfinedTaskQueue latestTaskQueue = new ThreadConfinedTaskQueue(); + private @LazyInit ThreadConfinedTaskQueue latestTaskQueue = new ThreadConfinedTaskQueue(); /** * This object is unsafely published, but avoids problematic races by relying exclusively on the @@ -131,9 +131,11 @@ private static final class ThreadConfinedTaskQueue { * All the states where thread != currentThread are identical for our purposes, and so even * though it's racy, we don't care which of those values we get, so no need to synchronize. */ - @CheckForNull Thread thread; + @CheckForNull @LazyInit Thread thread; + /** Only used by the thread associated with this object */ @CheckForNull Runnable nextTask; + /** Only used by the thread associated with this object */ @CheckForNull Executor nextExecutor; } @@ -308,7 +310,7 @@ private static final class TaskNonReentrantExecutor extends AtomicReference extends AbstractFuture.TrustedFuture implements Runnable { - @CheckForNull private ListenableFuture delegate; + @CheckForNull @LazyInit private ListenableFuture delegate; NonCancellationPropagatingFuture(final ListenableFuture delegate) { this.delegate = delegate; diff --git a/android/guava/src/com/google/common/util/concurrent/SequentialExecutor.java b/android/guava/src/com/google/common/util/concurrent/SequentialExecutor.java index ebc33178d0c5..2fcddadbcab4 100644 --- a/android/guava/src/com/google/common/util/concurrent/SequentialExecutor.java +++ b/android/guava/src/com/google/common/util/concurrent/SequentialExecutor.java @@ -25,6 +25,7 @@ import com.google.common.annotations.J2ktIncompatible; import com.google.common.base.Preconditions; import com.google.errorprone.annotations.concurrent.GuardedBy; +import com.google.errorprone.annotations.concurrent.LazyInit; import com.google.j2objc.annotations.RetainedWith; import java.util.ArrayDeque; import java.util.Deque; @@ -70,6 +71,7 @@ enum WorkerRunningState { private final Deque queue = new ArrayDeque<>(); /** see {@link WorkerRunningState} */ + @LazyInit @GuardedBy("queue") private WorkerRunningState workerRunningState = IDLE; diff --git a/android/guava/src/com/google/common/util/concurrent/TimeoutFuture.java b/android/guava/src/com/google/common/util/concurrent/TimeoutFuture.java index aca62305463f..b3f7f1346e5b 100644 --- a/android/guava/src/com/google/common/util/concurrent/TimeoutFuture.java +++ b/android/guava/src/com/google/common/util/concurrent/TimeoutFuture.java @@ -19,6 +19,7 @@ import com.google.common.annotations.GwtIncompatible; import com.google.common.annotations.J2ktIncompatible; import com.google.common.base.Preconditions; +import com.google.errorprone.annotations.concurrent.LazyInit; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; import java.util.concurrent.ScheduledExecutorService; @@ -75,8 +76,8 @@ final class TimeoutFuture extends FluentFuture.Trust * write-barriers). */ - @CheckForNull private ListenableFuture delegateRef; - @CheckForNull private ScheduledFuture timer; + @CheckForNull @LazyInit private ListenableFuture delegateRef; + @CheckForNull @LazyInit private ScheduledFuture timer; private TimeoutFuture(ListenableFuture delegate) { this.delegateRef = Preconditions.checkNotNull(delegate); @@ -84,7 +85,7 @@ private TimeoutFuture(ListenableFuture delegate) { /** A runnable that is called when the delegate or the timer completes. */ private static final class Fire implements Runnable { - @CheckForNull TimeoutFuture timeoutFutureRef; + @CheckForNull @LazyInit TimeoutFuture timeoutFutureRef; Fire(TimeoutFuture timeoutFuture) { this.timeoutFutureRef = timeoutFuture; diff --git a/guava/src/com/google/common/util/concurrent/AbstractCatchingFuture.java b/guava/src/com/google/common/util/concurrent/AbstractCatchingFuture.java index 8fa6500280d6..6555872a9744 100644 --- a/guava/src/com/google/common/util/concurrent/AbstractCatchingFuture.java +++ b/guava/src/com/google/common/util/concurrent/AbstractCatchingFuture.java @@ -26,6 +26,7 @@ import com.google.common.util.concurrent.internal.InternalFutureFailureAccess; import com.google.common.util.concurrent.internal.InternalFutures; import com.google.errorprone.annotations.ForOverride; +import com.google.errorprone.annotations.concurrent.LazyInit; import java.util.concurrent.ExecutionException; import java.util.concurrent.Executor; import javax.annotation.CheckForNull; @@ -62,9 +63,9 @@ abstract class AbstractCatchingFuture< * In certain circumstances, this field might theoretically not be visible to an afterDone() call * triggered by cancel(). For details, see the comments on the fields of TimeoutFuture. */ - @CheckForNull ListenableFuture inputFuture; - @CheckForNull Class exceptionType; - @CheckForNull F fallback; + @CheckForNull @LazyInit ListenableFuture inputFuture; + @CheckForNull @LazyInit Class exceptionType; + @CheckForNull @LazyInit F fallback; AbstractCatchingFuture( ListenableFuture inputFuture, Class exceptionType, F fallback) { diff --git a/guava/src/com/google/common/util/concurrent/AbstractTransformFuture.java b/guava/src/com/google/common/util/concurrent/AbstractTransformFuture.java index 3c5f30b63fb9..f23333c5dc1c 100644 --- a/guava/src/com/google/common/util/concurrent/AbstractTransformFuture.java +++ b/guava/src/com/google/common/util/concurrent/AbstractTransformFuture.java @@ -22,6 +22,7 @@ import com.google.common.annotations.GwtCompatible; import com.google.common.base.Function; import com.google.errorprone.annotations.ForOverride; +import com.google.errorprone.annotations.concurrent.LazyInit; import java.util.concurrent.CancellationException; import java.util.concurrent.ExecutionException; import java.util.concurrent.Executor; @@ -57,8 +58,8 @@ abstract class AbstractTransformFuture< * In certain circumstances, this field might theoretically not be visible to an afterDone() call * triggered by cancel(). For details, see the comments on the fields of TimeoutFuture. */ - @CheckForNull ListenableFuture inputFuture; - @CheckForNull F function; + @CheckForNull @LazyInit ListenableFuture inputFuture; + @CheckForNull @LazyInit F function; AbstractTransformFuture(ListenableFuture inputFuture, F function) { this.inputFuture = checkNotNull(inputFuture); diff --git a/guava/src/com/google/common/util/concurrent/AggregateFuture.java b/guava/src/com/google/common/util/concurrent/AggregateFuture.java index 35347741667d..a29430dee100 100644 --- a/guava/src/com/google/common/util/concurrent/AggregateFuture.java +++ b/guava/src/com/google/common/util/concurrent/AggregateFuture.java @@ -27,6 +27,7 @@ import com.google.common.collect.ImmutableCollection; import com.google.errorprone.annotations.ForOverride; import com.google.errorprone.annotations.OverridingMethodsMustInvokeSuper; +import com.google.errorprone.annotations.concurrent.LazyInit; import java.util.Set; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; @@ -55,7 +56,8 @@ abstract class AggregateFuture> futures; + @CheckForNull @LazyInit + private ImmutableCollection> futures; private final boolean allMustSucceed; private final boolean collectsValues; diff --git a/guava/src/com/google/common/util/concurrent/CollectionFuture.java b/guava/src/com/google/common/util/concurrent/CollectionFuture.java index 062aee7a79dc..445f6ccac305 100644 --- a/guava/src/com/google/common/util/concurrent/CollectionFuture.java +++ b/guava/src/com/google/common/util/concurrent/CollectionFuture.java @@ -20,6 +20,7 @@ import com.google.common.annotations.GwtCompatible; import com.google.common.collect.ImmutableCollection; import com.google.common.collect.Lists; +import com.google.errorprone.annotations.concurrent.LazyInit; import java.util.Collections; import java.util.List; import javax.annotation.CheckForNull; @@ -36,7 +37,7 @@ abstract class CollectionFuture> values; + @CheckForNull @LazyInit private List<@Nullable Present> values; CollectionFuture( ImmutableCollection> futures, diff --git a/guava/src/com/google/common/util/concurrent/CombinedFuture.java b/guava/src/com/google/common/util/concurrent/CombinedFuture.java index c22211164c40..fbbf113fa8be 100644 --- a/guava/src/com/google/common/util/concurrent/CombinedFuture.java +++ b/guava/src/com/google/common/util/concurrent/CombinedFuture.java @@ -19,6 +19,7 @@ import com.google.common.annotations.GwtCompatible; import com.google.common.collect.ImmutableCollection; +import com.google.errorprone.annotations.concurrent.LazyInit; import com.google.j2objc.annotations.WeakOuter; import java.util.concurrent.Callable; import java.util.concurrent.CancellationException; @@ -33,7 +34,7 @@ @ElementTypesAreNonnullByDefault final class CombinedFuture extends AggregateFuture<@Nullable Object, V> { - @CheckForNull private CombinedFutureInterruptibleTask task; + @CheckForNull @LazyInit private CombinedFutureInterruptibleTask task; CombinedFuture( ImmutableCollection> futures, diff --git a/guava/src/com/google/common/util/concurrent/ExecutionSequencer.java b/guava/src/com/google/common/util/concurrent/ExecutionSequencer.java index c335711c064f..4e13a9d0b315 100644 --- a/guava/src/com/google/common/util/concurrent/ExecutionSequencer.java +++ b/guava/src/com/google/common/util/concurrent/ExecutionSequencer.java @@ -26,9 +26,9 @@ import static java.util.Objects.requireNonNull; import com.google.common.annotations.J2ktIncompatible; +import com.google.errorprone.annotations.concurrent.LazyInit; import java.util.concurrent.Callable; import java.util.concurrent.Executor; -import java.util.concurrent.Future; import java.util.concurrent.atomic.AtomicReference; import javax.annotation.CheckForNull; import org.checkerframework.checker.nullness.qual.Nullable; @@ -100,7 +100,7 @@ public static ExecutionSequencer create() { private final AtomicReference> ref = new AtomicReference<>(immediateVoidFuture()); - private ThreadConfinedTaskQueue latestTaskQueue = new ThreadConfinedTaskQueue(); + private @LazyInit ThreadConfinedTaskQueue latestTaskQueue = new ThreadConfinedTaskQueue(); /** * This object is unsafely published, but avoids problematic races by relying exclusively on the @@ -131,9 +131,11 @@ private static final class ThreadConfinedTaskQueue { * All the states where thread != currentThread are identical for our purposes, and so even * though it's racy, we don't care which of those values we get, so no need to synchronize. */ - @CheckForNull Thread thread; + @CheckForNull @LazyInit Thread thread; + /** Only used by the thread associated with this object */ @CheckForNull Runnable nextTask; + /** Only used by the thread associated with this object */ @CheckForNull Executor nextExecutor; } @@ -308,7 +310,7 @@ private static final class TaskNonReentrantExecutor extends AtomicReference extends AbstractFuture.TrustedFuture implements Runnable { - @CheckForNull private ListenableFuture delegate; + @CheckForNull @LazyInit private ListenableFuture delegate; NonCancellationPropagatingFuture(final ListenableFuture delegate) { this.delegate = delegate; diff --git a/guava/src/com/google/common/util/concurrent/SequentialExecutor.java b/guava/src/com/google/common/util/concurrent/SequentialExecutor.java index ebc33178d0c5..2fcddadbcab4 100644 --- a/guava/src/com/google/common/util/concurrent/SequentialExecutor.java +++ b/guava/src/com/google/common/util/concurrent/SequentialExecutor.java @@ -25,6 +25,7 @@ import com.google.common.annotations.J2ktIncompatible; import com.google.common.base.Preconditions; import com.google.errorprone.annotations.concurrent.GuardedBy; +import com.google.errorprone.annotations.concurrent.LazyInit; import com.google.j2objc.annotations.RetainedWith; import java.util.ArrayDeque; import java.util.Deque; @@ -70,6 +71,7 @@ enum WorkerRunningState { private final Deque queue = new ArrayDeque<>(); /** see {@link WorkerRunningState} */ + @LazyInit @GuardedBy("queue") private WorkerRunningState workerRunningState = IDLE; diff --git a/guava/src/com/google/common/util/concurrent/TimeoutFuture.java b/guava/src/com/google/common/util/concurrent/TimeoutFuture.java index aca62305463f..b3f7f1346e5b 100644 --- a/guava/src/com/google/common/util/concurrent/TimeoutFuture.java +++ b/guava/src/com/google/common/util/concurrent/TimeoutFuture.java @@ -19,6 +19,7 @@ import com.google.common.annotations.GwtIncompatible; import com.google.common.annotations.J2ktIncompatible; import com.google.common.base.Preconditions; +import com.google.errorprone.annotations.concurrent.LazyInit; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; import java.util.concurrent.ScheduledExecutorService; @@ -75,8 +76,8 @@ final class TimeoutFuture extends FluentFuture.Trust * write-barriers). */ - @CheckForNull private ListenableFuture delegateRef; - @CheckForNull private ScheduledFuture timer; + @CheckForNull @LazyInit private ListenableFuture delegateRef; + @CheckForNull @LazyInit private ScheduledFuture timer; private TimeoutFuture(ListenableFuture delegate) { this.delegateRef = Preconditions.checkNotNull(delegate); @@ -84,7 +85,7 @@ private TimeoutFuture(ListenableFuture delegate) { /** A runnable that is called when the delegate or the timer completes. */ private static final class Fire implements Runnable { - @CheckForNull TimeoutFuture timeoutFutureRef; + @CheckForNull @LazyInit TimeoutFuture timeoutFutureRef; Fire(TimeoutFuture timeoutFuture) { this.timeoutFutureRef = timeoutFuture;