Skip to content

Commit 96aec22

Browse files
cpovirkGoogle Java Core Libraries
authored and
Google Java Core Libraries
committedFeb 12, 2025·
It turns out that we'd changed our choice of `Queue` in `MultimapsTest` once previously in cl/16428259 _without updating the clever comment about it later in the file_ 😱 RELNOTES=n/a PiperOrigin-RevId: 726065051
1 parent d650068 commit 96aec22

28 files changed

+106
-12
lines changed
 

‎android/guava-testlib/src/com/google/common/collect/testing/TestsForListsInJavaUtil.java

+4
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,8 @@ public List<String> create(String[] elements) {
188188
.createTestSuite();
189189
}
190190

191+
// We are testing LinkedList / testing our tests on LinkedList.
192+
@SuppressWarnings("JdkObsolete")
191193
public Test testsForLinkedList() {
192194
return ListTestSuiteBuilder.using(
193195
new TestStringListGenerator() {
@@ -322,6 +324,8 @@ public ListIterator<String> listIterator(int index) {
322324
.createTestSuite();
323325
}
324326

327+
// We are testing Vector / testing our tests on Vector.
328+
@SuppressWarnings("JdkObsolete")
325329
private Test testsForVector() {
326330
return ListTestSuiteBuilder.using(
327331
new TestStringListGenerator() {

‎android/guava-testlib/src/com/google/common/collect/testing/TestsForMapsInJavaUtil.java

+2
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,8 @@ public Test testsForHashtable() {
246246
return MapTestSuiteBuilder.using(
247247
new TestStringMapGenerator() {
248248
@Override
249+
// We are testing Hashtable / testing our tests on Hashtable.
250+
@SuppressWarnings("JdkObsolete")
249251
protected Map<String, String> create(Entry<String, String>[] entries) {
250252
return populate(new Hashtable<String, String>(), entries);
251253
}

‎android/guava-testlib/src/com/google/common/collect/testing/TestsForQueuesInJavaUtil.java

+2
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ public Test testsForLinkedList() {
111111
return QueueTestSuiteBuilder.using(
112112
new TestStringQueueGenerator() {
113113
@Override
114+
// We are testing LinkedList / testing our tests on LinkedList.
115+
@SuppressWarnings("JdkObsolete")
114116
public Queue<String> create(String[] elements) {
115117
return new LinkedList<>(MinimalCollection.of(elements));
116118
}

‎android/guava-testlib/src/com/google/common/testing/TearDownStack.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@
2222
import com.google.common.annotations.VisibleForTesting;
2323
import com.google.common.collect.Lists;
2424
import com.google.errorprone.annotations.concurrent.GuardedBy;
25+
import java.util.ArrayDeque;
2526
import java.util.ArrayList;
26-
import java.util.LinkedList;
27+
import java.util.Deque;
2728
import java.util.List;
2829
import java.util.logging.Level;
2930
import java.util.logging.Logger;
@@ -45,7 +46,7 @@ public class TearDownStack implements TearDownAccepter {
4546
@VisibleForTesting final Object lock = new Object();
4647

4748
@GuardedBy("lock")
48-
final LinkedList<TearDown> stack = new LinkedList<>();
49+
final Deque<TearDown> stack = new ArrayDeque<>();
4950

5051
private final boolean suppressThrows;
5152

‎android/guava-tests/test/com/google/common/collect/IterablesTest.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -1234,11 +1234,12 @@ public boolean apply(CharSequence input) {
12341234
}
12351235
};
12361236

1237+
@SuppressWarnings("UnnecessaryStringBuilder") // false positive in a weird case
12371238
public void testIndexOf_genericPredicate() {
12381239
List<CharSequence> sequences = Lists.newArrayList();
12391240
sequences.add("bob");
12401241
sequences.add(new StringBuilder("charlie"));
1241-
sequences.add(new StringBuffer("henry"));
1242+
sequences.add(new StringBuilder("henry"));
12421243
sequences.add(new StringBuilder("apple"));
12431244
sequences.add("lemon");
12441245

‎android/guava-tests/test/com/google/common/collect/IteratorsTest.java

+2
Original file line numberDiff line numberDiff line change
@@ -1158,6 +1158,8 @@ public void testAsEnumerationTypical() {
11581158
assertFalse(enumer.hasMoreElements());
11591159
}
11601160

1161+
// We're testing our asEnumeration method against a known-good implementation.
1162+
@SuppressWarnings("JdkObsolete")
11611163
private static Enumeration<Integer> enumerate(int... ints) {
11621164
Vector<Integer> vector = new Vector<>(Ints.asList(ints));
11631165
return vector.elements();

‎android/guava-tests/test/com/google/common/collect/ListsImplTest.java

+2
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,8 @@ protected LinkedListExample(String name) {
266266
}
267267

268268
@Override
269+
// We are testing our utilities on LinkedList.
270+
@SuppressWarnings("JdkObsolete")
269271
public <T> List<T> createList(Class<T> listType, Collection<? extends T> contents) {
270272
return new LinkedList<>(contents);
271273
}

‎android/guava-tests/test/com/google/common/collect/MultimapsTest.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,11 @@ public E get() {
543543

544544
private static class QueueSupplier extends CountingSupplier<Queue<Integer>> {
545545
@Override
546+
/*
547+
* We need a Queue that implements equals() for the equality tests we perform after
548+
* reserializing the multimap.
549+
*/
550+
@SuppressWarnings("JdkObsolete")
546551
public Queue<Integer> getImpl() {
547552
return new LinkedList<>();
548553
}
@@ -587,7 +592,7 @@ public boolean addAll(Collection<? extends Integer> collection) {
587592
}
588593

589594
public void testNewMultimap() {
590-
// The ubiquitous EnumArrayBlockingQueueMultimap
595+
// The ubiquitous EnumLinkedListMultimap
591596
CountingSupplier<Queue<Integer>> factory = new QueueSupplier();
592597

593598
Map<Color, Collection<Integer>> map = Maps.newEnumMap(Color.class);

‎android/guava/src/com/google/common/collect/ForwardingSortedMap.java

+5
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@
5050
* @since 2.0
5151
*/
5252
@GwtCompatible
53+
/*
54+
* We provide and encourage use of ForwardingNavigableSet over this class, but we still provide this
55+
* one to preserve compatibility.
56+
*/
57+
@SuppressWarnings("JdkObsolete")
5358
public abstract class ForwardingSortedMap<K extends @Nullable Object, V extends @Nullable Object>
5459
extends ForwardingMap<K, V> implements SortedMap<K, V> {
5560
// TODO(lowasser): identify places where thread safety is actually lost

‎android/guava/src/com/google/common/collect/ForwardingSortedSet.java

+5
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@
5353
* @since 2.0
5454
*/
5555
@GwtCompatible
56+
/*
57+
* We provide and encourage use of ForwardingNavigableSet over this class, but we still provide this
58+
* one to preserve compatibility.
59+
*/
60+
@SuppressWarnings("JdkObsolete")
5661
public abstract class ForwardingSortedSet<E extends @Nullable Object> extends ForwardingSet<E>
5762
implements SortedSet<E> {
5863

‎android/guava/src/com/google/common/collect/Iterators.java

+2
Original file line numberDiff line numberDiff line change
@@ -1159,6 +1159,8 @@ public T next() {
11591159
* <p>The {@code Iterable} equivalent of this method is either {@link Collections#enumeration} (if
11601160
* you have a {@link Collection}), or {@code Iterators.asEnumeration(collection.iterator())}.
11611161
*/
1162+
// This is an adapter for cases in which users do need an Enumeration for whatever reason.
1163+
@SuppressWarnings("JdkObsolete")
11621164
public static <T extends @Nullable Object> Enumeration<T> asEnumeration(Iterator<T> iterator) {
11631165
checkNotNull(iterator);
11641166
return new Enumeration<T>() {

‎android/guava/src/com/google/common/collect/Lists.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,10 @@ static int computeArrayListCapacity(int arraySize) {
226226
* syntax</a>.
227227
*/
228228
@GwtCompatible(serializable = true)
229-
@SuppressWarnings("NonApiType") // acts as a direct substitute for a constructor call
229+
@SuppressWarnings({
230+
"NonApiType", // acts as a direct substitute for a constructor call
231+
"JdkObsolete", // We recommend against this method but need to keep it for compatibility.
232+
})
230233
public static <E extends @Nullable Object> LinkedList<E> newLinkedList() {
231234
return new LinkedList<>();
232235
}

‎android/guava/src/com/google/common/collect/MultimapBuilder.java

+11-1
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,8 @@ private enum LinkedListSupplier implements Supplier<List<?>> {
203203
}
204204

205205
@Override
206+
// We recommend against linkedListValues but need to keep it for compatibility.
207+
@SuppressWarnings("JdkObsolete")
206208
public List<?> get() {
207209
return new LinkedList<>();
208210
}
@@ -302,7 +304,15 @@ public abstract static class MultimapBuilderWithKeys<K0 extends @Nullable Object
302304
};
303305
}
304306

305-
/** Uses a {@link LinkedList} to store value collections. */
307+
/**
308+
* Uses a {@link LinkedList} to store value collections.
309+
*
310+
* <p><b>Performance note:</b> {@link ArrayList} and {@link java.util.ArrayDeque} consistently
311+
* outperform {@code LinkedList} except in certain rare and specific situations. Unless you have
312+
* spent a lot of time benchmarking your specific needs, use one of those instead. (However, we
313+
* do not currently offer a {@link Multimap} implementation based on {@link
314+
* java.util.ArrayDeque}.)
315+
*/
306316
public ListMultimapBuilder<K0, @Nullable Object> linkedListValues() {
307317
return new ListMultimapBuilder<K0, @Nullable Object>() {
308318
@Override

‎guava-testlib/src/com/google/common/collect/testing/TestsForListsInJavaUtil.java

+4
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,8 @@ public List<String> create(String[] elements) {
192192
.createTestSuite();
193193
}
194194

195+
// We are testing LinkedList / testing our tests on LinkedList.
196+
@SuppressWarnings("JdkObsolete")
195197
public Test testsForLinkedList() {
196198
return ListTestSuiteBuilder.using(
197199
new TestStringListGenerator() {
@@ -326,6 +328,8 @@ public ListIterator<String> listIterator(int index) {
326328
.createTestSuite();
327329
}
328330

331+
// We are testing Vector / testing our tests on Vector.
332+
@SuppressWarnings("JdkObsolete")
329333
private Test testsForVector() {
330334
return ListTestSuiteBuilder.using(
331335
new TestStringListGenerator() {

‎guava-testlib/src/com/google/common/collect/testing/TestsForMapsInJavaUtil.java

+2
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,8 @@ public Test testsForHashtable() {
324324
return MapTestSuiteBuilder.using(
325325
new TestStringMapGenerator() {
326326
@Override
327+
// We are testing Hashtable / testing our tests on Hashtable.
328+
@SuppressWarnings("JdkObsolete")
327329
protected Map<String, String> create(Entry<String, String>[] entries) {
328330
return populate(new Hashtable<String, String>(), entries);
329331
}

‎guava-testlib/src/com/google/common/collect/testing/TestsForQueuesInJavaUtil.java

+2
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ public Test testsForLinkedList() {
144144
return QueueTestSuiteBuilder.using(
145145
new TestStringQueueGenerator() {
146146
@Override
147+
// We are testing LinkedList / testing our tests on LinkedList.
148+
@SuppressWarnings("JdkObsolete")
147149
public Queue<String> create(String[] elements) {
148150
return new LinkedList<>(MinimalCollection.of(elements));
149151
}

‎guava-testlib/src/com/google/common/testing/TearDownStack.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@
2222
import com.google.common.annotations.VisibleForTesting;
2323
import com.google.common.collect.Lists;
2424
import com.google.errorprone.annotations.concurrent.GuardedBy;
25+
import java.util.ArrayDeque;
2526
import java.util.ArrayList;
26-
import java.util.LinkedList;
27+
import java.util.Deque;
2728
import java.util.List;
2829
import java.util.logging.Level;
2930
import java.util.logging.Logger;
@@ -45,7 +46,7 @@ public class TearDownStack implements TearDownAccepter {
4546
@VisibleForTesting final Object lock = new Object();
4647

4748
@GuardedBy("lock")
48-
final LinkedList<TearDown> stack = new LinkedList<>();
49+
final Deque<TearDown> stack = new ArrayDeque<>();
4950

5051
private final boolean suppressThrows;
5152

‎guava-tests/benchmark/com/google/common/collect/StreamsBenchmark.java

+2
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ public class StreamsBenchmark {
4040
@Param({"1", "10", "100", "1000", "10000"})
4141
private int size;
4242

43+
// This is a benchmark of streams, including those from LinkedList.
44+
@SuppressWarnings("JdkObsolete")
4345
enum CollectionType {
4446
ARRAY_LIST(ArrayList::new),
4547
LINKED_LIST(LinkedList::new);

‎guava-tests/test/com/google/common/collect/IterablesTest.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -1271,11 +1271,12 @@ public boolean apply(CharSequence input) {
12711271
}
12721272
};
12731273

1274+
@SuppressWarnings("UnnecessaryStringBuilder") // false positive in a weird case
12741275
public void testIndexOf_genericPredicate() {
12751276
List<CharSequence> sequences = Lists.newArrayList();
12761277
sequences.add("bob");
12771278
sequences.add(new StringBuilder("charlie"));
1278-
sequences.add(new StringBuffer("henry"));
1279+
sequences.add(new StringBuilder("henry"));
12791280
sequences.add(new StringBuilder("apple"));
12801281
sequences.add("lemon");
12811282

‎guava-tests/test/com/google/common/collect/IteratorsTest.java

+2
Original file line numberDiff line numberDiff line change
@@ -1158,6 +1158,8 @@ public void testAsEnumerationTypical() {
11581158
assertFalse(enumer.hasMoreElements());
11591159
}
11601160

1161+
// We're testing our asEnumeration method against a known-good implementation.
1162+
@SuppressWarnings("JdkObsolete")
11611163
private static Enumeration<Integer> enumerate(int... ints) {
11621164
Vector<Integer> vector = new Vector<>(Ints.asList(ints));
11631165
return vector.elements();

‎guava-tests/test/com/google/common/collect/ListsImplTest.java

+2
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,8 @@ protected LinkedListExample(String name) {
266266
}
267267

268268
@Override
269+
// We are testing our utilities on LinkedList.
270+
@SuppressWarnings("JdkObsolete")
269271
public <T> List<T> createList(Class<T> listType, Collection<? extends T> contents) {
270272
return new LinkedList<>(contents);
271273
}

‎guava-tests/test/com/google/common/collect/MultimapsTest.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,11 @@ public E get() {
614614

615615
private static class QueueSupplier extends CountingSupplier<Queue<Integer>> {
616616
@Override
617+
/*
618+
* We need a Queue that implements equals() for the equality tests we perform after
619+
* reserializing the multimap.
620+
*/
621+
@SuppressWarnings("JdkObsolete")
617622
public Queue<Integer> getImpl() {
618623
return new LinkedList<>();
619624
}
@@ -658,7 +663,7 @@ public boolean addAll(Collection<? extends Integer> collection) {
658663
}
659664

660665
public void testNewMultimap() {
661-
// The ubiquitous EnumArrayBlockingQueueMultimap
666+
// The ubiquitous EnumLinkedListMultimap
662667
CountingSupplier<Queue<Integer>> factory = new QueueSupplier();
663668

664669
Map<Color, Collection<Integer>> map = Maps.newEnumMap(Color.class);

‎guava-tests/test/com/google/common/collect/StreamsTest.java

+4
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ public void testFindLast_refStream() {
9292
assertThat(findLast(Stream.of("a", "b", "c", "d"))).hasValue("d");
9393

9494
// test with a large, not-subsized Spliterator
95+
@SuppressWarnings("JdkObsolete")
9596
List<Integer> list =
9697
IntStream.rangeClosed(0, 10000).boxed().collect(Collectors.toCollection(LinkedList::new));
9798
assertThat(findLast(list.stream())).hasValue(10000);
@@ -105,6 +106,7 @@ public void testFindLast_intStream() {
105106
assertThat(findLast(IntStream.of(1, 2, 3, 4, 5))).isEqualTo(OptionalInt.of(5));
106107

107108
// test with a large, not-subsized Spliterator
109+
@SuppressWarnings("JdkObsolete")
108110
List<Integer> list =
109111
IntStream.rangeClosed(0, 10000).boxed().collect(Collectors.toCollection(LinkedList::new));
110112
assertThat(findLast(list.stream().mapToInt(i -> i))).isEqualTo(OptionalInt.of(10000));
@@ -119,6 +121,7 @@ public void testFindLast_longStream() {
119121
assertThat(findLast(LongStream.of(1, 2, 3, 4, 5))).isEqualTo(OptionalLong.of(5));
120122

121123
// test with a large, not-subsized Spliterator
124+
@SuppressWarnings("JdkObsolete")
122125
List<Long> list =
123126
LongStream.rangeClosed(0, 10000).boxed().collect(Collectors.toCollection(LinkedList::new));
124127
assertThat(findLast(list.stream().mapToLong(i -> i))).isEqualTo(OptionalLong.of(10000));
@@ -133,6 +136,7 @@ public void testFindLast_doubleStream() {
133136
assertThat(findLast(DoubleStream.of(1, 2, 3, 4, 5))).isEqualTo(OptionalDouble.of(5));
134137

135138
// test with a large, not-subsized Spliterator
139+
@SuppressWarnings("JdkObsolete")
136140
List<Long> list =
137141
LongStream.rangeClosed(0, 10000).boxed().collect(Collectors.toCollection(LinkedList::new));
138142
assertThat(findLast(list.stream().mapToDouble(i -> i))).isEqualTo(OptionalDouble.of(10000));

‎guava/src/com/google/common/collect/ForwardingSortedMap.java

+5
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@
5050
* @since 2.0
5151
*/
5252
@GwtCompatible
53+
/*
54+
* We provide and encourage use of ForwardingNavigableSet over this class, but we still provide this
55+
* one to preserve compatibility.
56+
*/
57+
@SuppressWarnings("JdkObsolete")
5358
public abstract class ForwardingSortedMap<K extends @Nullable Object, V extends @Nullable Object>
5459
extends ForwardingMap<K, V> implements SortedMap<K, V> {
5560
// TODO(lowasser): identify places where thread safety is actually lost

‎guava/src/com/google/common/collect/ForwardingSortedSet.java

+5
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@
5353
* @since 2.0
5454
*/
5555
@GwtCompatible
56+
/*
57+
* We provide and encourage use of ForwardingNavigableSet over this class, but we still provide this
58+
* one to preserve compatibility.
59+
*/
60+
@SuppressWarnings("JdkObsolete")
5661
public abstract class ForwardingSortedSet<E extends @Nullable Object> extends ForwardingSet<E>
5762
implements SortedSet<E> {
5863

‎guava/src/com/google/common/collect/Iterators.java

+2
Original file line numberDiff line numberDiff line change
@@ -1159,6 +1159,8 @@ public T next() {
11591159
* <p>The {@code Iterable} equivalent of this method is either {@link Collections#enumeration} (if
11601160
* you have a {@link Collection}), or {@code Iterators.asEnumeration(collection.iterator())}.
11611161
*/
1162+
// This is an adapter for cases in which users do need an Enumeration for whatever reason.
1163+
@SuppressWarnings("JdkObsolete")
11621164
public static <T extends @Nullable Object> Enumeration<T> asEnumeration(Iterator<T> iterator) {
11631165
checkNotNull(iterator);
11641166
return new Enumeration<T>() {

‎guava/src/com/google/common/collect/Lists.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,10 @@ static int computeArrayListCapacity(int arraySize) {
227227
* syntax</a>.
228228
*/
229229
@GwtCompatible(serializable = true)
230-
@SuppressWarnings("NonApiType") // acts as a direct substitute for a constructor call
230+
@SuppressWarnings({
231+
"NonApiType", // acts as a direct substitute for a constructor call
232+
"JdkObsolete", // We recommend against this method but need to keep it for compatibility.
233+
})
231234
public static <E extends @Nullable Object> LinkedList<E> newLinkedList() {
232235
return new LinkedList<>();
233236
}

‎guava/src/com/google/common/collect/MultimapBuilder.java

+11-1
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,8 @@ private enum LinkedListSupplier implements Supplier<List<?>> {
203203
}
204204

205205
@Override
206+
// We recommend against linkedListValues but need to keep it for compatibility.
207+
@SuppressWarnings("JdkObsolete")
206208
public List<?> get() {
207209
return new LinkedList<>();
208210
}
@@ -302,7 +304,15 @@ public abstract static class MultimapBuilderWithKeys<K0 extends @Nullable Object
302304
};
303305
}
304306

305-
/** Uses a {@link LinkedList} to store value collections. */
307+
/**
308+
* Uses a {@link LinkedList} to store value collections.
309+
*
310+
* <p><b>Performance note:</b> {@link ArrayList} and {@link java.util.ArrayDeque} consistently
311+
* outperform {@code LinkedList} except in certain rare and specific situations. Unless you have
312+
* spent a lot of time benchmarking your specific needs, use one of those instead. (However, we
313+
* do not currently offer a {@link Multimap} implementation based on {@link
314+
* java.util.ArrayDeque}.)
315+
*/
306316
public ListMultimapBuilder<K0, @Nullable Object> linkedListValues() {
307317
return new ListMultimapBuilder<K0, @Nullable Object>() {
308318
@Override

0 commit comments

Comments
 (0)
Please sign in to comment.