Skip to content

Commit 461b7bb

Browse files
cpovirknetdpb
authored andcommitted
Suppress TSAN errors for benign races.
Compare other usages of `@LazyInit` on collection views, such as `HashBiMap.inverse` and `AbstractTable.cellSet`. RELNOTES=n/a ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=345023158
1 parent 1a020b7 commit 461b7bb

File tree

4 files changed

+24
-20
lines changed

4 files changed

+24
-20
lines changed

android/guava/src/com/google/common/collect/AbstractMultimap.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import com.google.common.annotations.GwtCompatible;
2222
import com.google.errorprone.annotations.CanIgnoreReturnValue;
23+
import com.google.errorprone.annotations.concurrent.LazyInit;
2324
import com.google.j2objc.annotations.WeakOuter;
2425
import java.util.AbstractCollection;
2526
import java.util.Collection;
@@ -105,7 +106,7 @@ public Collection<V> replaceValues(@NullableDecl K key, Iterable<? extends V> va
105106
return result;
106107
}
107108

108-
@NullableDecl private transient Collection<Entry<K, V>> entries;
109+
@LazyInit @NullableDecl private transient Collection<Entry<K, V>> entries;
109110

110111
@Override
111112
public Collection<Entry<K, V>> entries() {
@@ -143,7 +144,7 @@ public boolean equals(@NullableDecl Object obj) {
143144

144145
abstract Iterator<Entry<K, V>> entryIterator();
145146

146-
@NullableDecl private transient Set<K> keySet;
147+
@LazyInit @NullableDecl private transient Set<K> keySet;
147148

148149
@Override
149150
public Set<K> keySet() {
@@ -153,7 +154,7 @@ public Set<K> keySet() {
153154

154155
abstract Set<K> createKeySet();
155156

156-
@NullableDecl private transient Multiset<K> keys;
157+
@LazyInit @NullableDecl private transient Multiset<K> keys;
157158

158159
@Override
159160
public Multiset<K> keys() {
@@ -163,7 +164,7 @@ public Multiset<K> keys() {
163164

164165
abstract Multiset<K> createKeys();
165166

166-
@NullableDecl private transient Collection<V> values;
167+
@LazyInit @NullableDecl private transient Collection<V> values;
167168

168169
@Override
169170
public Collection<V> values() {
@@ -200,7 +201,7 @@ Iterator<V> valueIterator() {
200201
return Maps.valueIterator(entries().iterator());
201202
}
202203

203-
@NullableDecl private transient Map<K, Collection<V>> asMap;
204+
@LazyInit @NullableDecl private transient Map<K, Collection<V>> asMap;
204205

205206
@Override
206207
public Map<K, Collection<V>> asMap() {

android/guava/src/com/google/common/collect/Multimaps.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import com.google.common.base.Supplier;
3030
import com.google.common.collect.Maps.EntryTransformer;
3131
import com.google.errorprone.annotations.CanIgnoreReturnValue;
32+
import com.google.errorprone.annotations.concurrent.LazyInit;
3233
import com.google.j2objc.annotations.Weak;
3334
import com.google.j2objc.annotations.WeakOuter;
3435
import java.io.IOException;
@@ -539,11 +540,11 @@ public static <K, V> Multimap<K, V> unmodifiableMultimap(ImmutableMultimap<K, V>
539540
private static class UnmodifiableMultimap<K, V> extends ForwardingMultimap<K, V>
540541
implements Serializable {
541542
final Multimap<K, V> delegate;
542-
@NullableDecl transient Collection<Entry<K, V>> entries;
543-
@NullableDecl transient Multiset<K> keys;
544-
@NullableDecl transient Set<K> keySet;
545-
@NullableDecl transient Collection<V> values;
546-
@NullableDecl transient Map<K, Collection<V>> map;
543+
@LazyInit @NullableDecl transient Collection<Entry<K, V>> entries;
544+
@LazyInit @NullableDecl transient Multiset<K> keys;
545+
@LazyInit @NullableDecl transient Set<K> keySet;
546+
@LazyInit @NullableDecl transient Collection<V> values;
547+
@LazyInit @NullableDecl transient Map<K, Collection<V>> map;
547548

548549
UnmodifiableMultimap(final Multimap<K, V> delegate) {
549550
this.delegate = checkNotNull(delegate);

guava/src/com/google/common/collect/AbstractMultimap.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import com.google.common.annotations.GwtCompatible;
2222
import com.google.errorprone.annotations.CanIgnoreReturnValue;
23+
import com.google.errorprone.annotations.concurrent.LazyInit;
2324
import com.google.j2objc.annotations.WeakOuter;
2425
import java.util.AbstractCollection;
2526
import java.util.Collection;
@@ -107,7 +108,7 @@ public Collection<V> replaceValues(@Nullable K key, Iterable<? extends V> values
107108
return result;
108109
}
109110

110-
private transient @Nullable Collection<Entry<K, V>> entries;
111+
@LazyInit private transient @Nullable Collection<Entry<K, V>> entries;
111112

112113
@Override
113114
public Collection<Entry<K, V>> entries() {
@@ -155,7 +156,7 @@ Spliterator<Entry<K, V>> entrySpliterator() {
155156
entryIterator(), size(), (this instanceof SetMultimap) ? Spliterator.DISTINCT : 0);
156157
}
157158

158-
private transient @Nullable Set<K> keySet;
159+
@LazyInit private transient @Nullable Set<K> keySet;
159160

160161
@Override
161162
public Set<K> keySet() {
@@ -165,7 +166,7 @@ public Set<K> keySet() {
165166

166167
abstract Set<K> createKeySet();
167168

168-
private transient @Nullable Multiset<K> keys;
169+
@LazyInit private transient @Nullable Multiset<K> keys;
169170

170171
@Override
171172
public Multiset<K> keys() {
@@ -175,7 +176,7 @@ public Multiset<K> keys() {
175176

176177
abstract Multiset<K> createKeys();
177178

178-
private transient @Nullable Collection<V> values;
179+
@LazyInit private transient @Nullable Collection<V> values;
179180

180181
@Override
181182
public Collection<V> values() {
@@ -221,7 +222,7 @@ Spliterator<V> valueSpliterator() {
221222
return Spliterators.spliterator(valueIterator(), size(), 0);
222223
}
223224

224-
private transient @Nullable Map<K, Collection<V>> asMap;
225+
@LazyInit private transient @Nullable Map<K, Collection<V>> asMap;
225226

226227
@Override
227228
public Map<K, Collection<V>> asMap() {

guava/src/com/google/common/collect/Multimaps.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import com.google.common.base.Supplier;
3030
import com.google.common.collect.Maps.EntryTransformer;
3131
import com.google.errorprone.annotations.CanIgnoreReturnValue;
32+
import com.google.errorprone.annotations.concurrent.LazyInit;
3233
import com.google.j2objc.annotations.Weak;
3334
import com.google.j2objc.annotations.WeakOuter;
3435
import java.io.IOException;
@@ -626,11 +627,11 @@ public static <K, V> Multimap<K, V> unmodifiableMultimap(ImmutableMultimap<K, V>
626627
private static class UnmodifiableMultimap<K, V> extends ForwardingMultimap<K, V>
627628
implements Serializable {
628629
final Multimap<K, V> delegate;
629-
transient @Nullable Collection<Entry<K, V>> entries;
630-
transient @Nullable Multiset<K> keys;
631-
transient @Nullable Set<K> keySet;
632-
transient @Nullable Collection<V> values;
633-
transient @Nullable Map<K, Collection<V>> map;
630+
@LazyInit transient @Nullable Collection<Entry<K, V>> entries;
631+
@LazyInit transient @Nullable Multiset<K> keys;
632+
@LazyInit transient @Nullable Set<K> keySet;
633+
@LazyInit transient @Nullable Collection<V> values;
634+
@LazyInit transient @Nullable Map<K, Collection<V>> map;
634635

635636
UnmodifiableMultimap(final Multimap<K, V> delegate) {
636637
this.delegate = checkNotNull(delegate);

0 commit comments

Comments
 (0)