Skip to content

Commit 3618043

Browse files
cpovirkGoogle Java Core Libraries
authored and
Google Java Core Libraries
committed
Address some UnusedVariable warnings.
And perform a few tiny other cleanups. RELNOTES=n/a PiperOrigin-RevId: 648782393
1 parent 9ba5fea commit 3618043

File tree

50 files changed

+174
-288
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+174
-288
lines changed

android/guava-testlib/src/com/google/common/util/concurrent/testing/SameThreadScheduledExecutorService.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,11 +148,9 @@ public <V> ListenableScheduledFuture<V> schedule(
148148
return new ImmediateScheduledFuture<>(delegateFuture);
149149
}
150150

151-
private static class ImmediateScheduledFuture<V> extends SimpleForwardingListenableFuture<V>
151+
private static final class ImmediateScheduledFuture<V> extends SimpleForwardingListenableFuture<V>
152152
implements ListenableScheduledFuture<V> {
153-
private ExecutionException exception;
154-
155-
protected ImmediateScheduledFuture(ListenableFuture<V> future) {
153+
ImmediateScheduledFuture(ListenableFuture<V> future) {
156154
super(future);
157155
}
158156

android/guava-testlib/test/com/google/common/testing/GcFinalizationTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,43 +44,43 @@ public class GcFinalizationTest extends TestCase {
4444

4545
public void testAwait_CountDownLatch() {
4646
final CountDownLatch latch = new CountDownLatch(1);
47-
Object x =
47+
Object unused =
4848
new Object() {
4949
@Override
5050
protected void finalize() {
5151
latch.countDown();
5252
}
5353
};
54-
x = null; // Hint to the JIT that x is unreachable
54+
unused = null; // Hint to the JIT that unused is unreachable
5555
GcFinalization.await(latch);
5656
assertEquals(0, latch.getCount());
5757
}
5858

5959
public void testAwaitDone_Future() {
6060
final SettableFuture<@Nullable Void> future = SettableFuture.create();
61-
Object x =
61+
Object unused =
6262
new Object() {
6363
@Override
6464
protected void finalize() {
6565
future.set(null);
6666
}
6767
};
68-
x = null; // Hint to the JIT that x is unreachable
68+
unused = null; // Hint to the JIT that unused is unreachable
6969
GcFinalization.awaitDone(future);
7070
assertTrue(future.isDone());
7171
assertFalse(future.isCancelled());
7272
}
7373

7474
public void testAwaitDone_Future_Cancel() {
7575
final SettableFuture<@Nullable Void> future = SettableFuture.create();
76-
Object x =
76+
Object unused =
7777
new Object() {
7878
@Override
7979
protected void finalize() {
8080
future.cancel(false);
8181
}
8282
};
83-
x = null; // Hint to the JIT that x is unreachable
83+
unused = null; // Hint to the JIT that unused is unreachable
8484
GcFinalization.awaitDone(future);
8585
assertTrue(future.isDone());
8686
assertTrue(future.isCancelled());

android/guava-tests/benchmark/com/google/common/base/CharMatcherBenchmark.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ void setUp() {
7878
if (size == Size.SMALL) {
7979
BitSet tmp = new BitSet();
8080
matcher.setBits(tmp);
81-
int matchedCharCount = tmp.cardinality();
8281
this.matcher = SmallCharMatcher.from(tmp, "");
8382
}
8483
this.string = checkString(length, percent, config.matchingChars, new Random(), forceSlow, web);

android/guava-tests/benchmark/com/google/common/base/SplitterBenchmark.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,20 +45,24 @@ void setUp() {
4545
}
4646

4747
@Benchmark
48-
void charSplitter(int reps) {
48+
int charSplitter(int reps) {
4949
int total = 0;
5050

5151
for (int i = 0; i < reps; i++) {
5252
total += Iterables.size(CHAR_SPLITTER.split(input));
5353
}
54+
55+
return total;
5456
}
5557

5658
@Benchmark
57-
void stringSplitter(int reps) {
59+
int stringSplitter(int reps) {
5860
int total = 0;
5961

6062
for (int i = 0; i < reps; i++) {
6163
total += Iterables.size(STRING_SPLITTER.split(input));
6264
}
65+
66+
return total;
6367
}
6468
}

android/guava-tests/benchmark/com/google/common/collect/MultisetIteratorBenchmark.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ void setUp() {
4848
int sizeRemaining = size;
4949

5050
// TODO(kevinb): generate better test contents for multisets
51-
for (int i = 0; sizeRemaining > 0; i++) {
51+
while (sizeRemaining > 0) {
5252
// The JVM will return interned values for small ints.
5353
Integer value = random.nextInt(1000) + 128;
5454
int count = Math.min(random.nextInt(10) + 1, sizeRemaining);

android/guava-tests/test/com/google/common/base/FunctionsTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ public void testCompositionWildcard() {
280280

281281
Function<Object, String> numberToSpanish = Functions.constant("Yo no se");
282282

283-
Function<String, String> japaneseToSpanish =
283+
Function<String, String> unusedJapaneseToSpanish =
284284
Functions.compose(numberToSpanish, japaneseToInteger);
285285
}
286286

android/guava-tests/test/com/google/common/cache/LocalCacheTest.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1959,7 +1959,7 @@ public void testRemoveEntry() {
19591959
table.set(0, entry);
19601960
segment.count = 1;
19611961
assertTrue(segment.removeEntry(entry, hash, RemovalCause.COLLECTED));
1962-
assertNotificationEnqueued(map, key, value, hash);
1962+
assertNotificationEnqueued(map, key, value);
19631963
assertTrue(map.removalNotificationQueue.isEmpty());
19641964
assertFalse(segment.accessQueue.contains(entry));
19651965
assertFalse(segment.writeQueue.contains(entry));
@@ -2068,8 +2068,7 @@ public void testRemoveComputingValue() {
20682068
assertTrue(segment.removeLoadingValue(key, hash, valueRef));
20692069
}
20702070

2071-
private static <K, V> void assertNotificationEnqueued(
2072-
LocalCache<K, V> map, K key, V value, int hash) {
2071+
private static <K, V> void assertNotificationEnqueued(LocalCache<K, V> map, K key, V value) {
20732072
RemovalNotification<K, V> notification = map.removalNotificationQueue.poll();
20742073
assertSame(key, notification.getKey());
20752074
assertSame(value, notification.getValue());
@@ -2595,7 +2594,7 @@ public void testNullParameters() throws Exception {
25952594
NullPointerTester tester = new NullPointerTester();
25962595
tester.testAllPublicInstanceMethods(makeLocalCache(createCacheBuilder()));
25972596
CacheLoader<Object, Object> loader = identityLoader();
2598-
tester.testAllPublicInstanceMethods(makeLocalCache(createCacheBuilder()));
2597+
tester.testAllPublicInstanceMethods(makeLocalCache(createCacheBuilder(), loader));
25992598
}
26002599

26012600
public void testSerializationProxyLoading() {

android/guava-tests/test/com/google/common/cache/LocalLoadingCacheTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ public void testStats() {
124124
assertEquals(3.0 / 4, stats.missRate());
125125
assertEquals(3, stats.loadCount());
126126
assertTrue(stats.totalLoadTime() >= totalLoadTime);
127-
totalLoadTime = stats.totalLoadTime();
128127
assertTrue(stats.averageLoadPenalty() >= 0.0);
129128
assertEquals(1, stats.evictionCount());
130129
}

android/guava-tests/test/com/google/common/cache/PopulatedCachesTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public class PopulatedCachesTest extends TestCase {
5555
public void testSize_populated() {
5656
for (LoadingCache<Object, Object> cache : caches()) {
5757
// don't let the entries get GCed
58-
List<Entry<Object, Object>> warmed = warmUp(cache);
58+
List<Entry<Object, Object>> unused = warmUp(cache);
5959
assertEquals(WARMUP_SIZE, cache.size());
6060
assertMapSize(cache.asMap(), WARMUP_SIZE);
6161
checkValidState(cache);
@@ -125,7 +125,7 @@ public void testPutIfAbsent_populated() {
125125
public void testPutAll_populated() {
126126
for (LoadingCache<Object, Object> cache : caches()) {
127127
// don't let the entries get GCed
128-
List<Entry<Object, Object>> warmed = warmUp(cache);
128+
List<Entry<Object, Object>> unused = warmUp(cache);
129129
Object newKey = new Object();
130130
Object newValue = new Object();
131131
cache.asMap().putAll(ImmutableMap.of(newKey, newValue));

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -409,11 +409,7 @@ public void testExhaustive() {
409409
}
410410

411411
if (anyOverlaps) {
412-
assertThrows(
413-
IllegalArgumentException.class,
414-
() -> {
415-
RangeSet<Integer> copy = ImmutableRangeSet.copyOf(subset);
416-
});
412+
assertThrows(IllegalArgumentException.class, () -> ImmutableRangeSet.copyOf(subset));
417413
} else {
418414
RangeSet<Integer> copy = ImmutableRangeSet.copyOf(subset);
419415
assertEquals(mutable, copy);

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -826,20 +826,20 @@ public int compareTo(SelfComparableExample o) {
826826
}
827827

828828
public void testBuilderGenerics_SelfComparable() {
829-
ImmutableSortedMap.Builder<SelfComparableExample, Object> natural =
829+
ImmutableSortedMap.Builder<SelfComparableExample, Object> unusedNatural =
830830
ImmutableSortedMap.naturalOrder();
831831

832-
ImmutableSortedMap.Builder<SelfComparableExample, Object> reverse =
832+
ImmutableSortedMap.Builder<SelfComparableExample, Object> unusedReverse =
833833
ImmutableSortedMap.reverseOrder();
834834
}
835835

836836
private static class SuperComparableExample extends SelfComparableExample {}
837837

838838
public void testBuilderGenerics_SuperComparable() {
839-
ImmutableSortedMap.Builder<SuperComparableExample, Object> natural =
839+
ImmutableSortedMap.Builder<SuperComparableExample, Object> unusedNatural =
840840
ImmutableSortedMap.naturalOrder();
841841

842-
ImmutableSortedMap.Builder<SuperComparableExample, Object> reverse =
842+
ImmutableSortedMap.Builder<SuperComparableExample, Object> unusedReverse =
843843
ImmutableSortedMap.reverseOrder();
844844
}
845845
}

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,20 @@ public class MultimapBuilderTest extends TestCase {
4343
@J2ktIncompatible
4444
@GwtIncompatible // doesn't build without explicit type parameters on build() methods
4545
public void testGenerics() {
46-
ListMultimap<String, Integer> a = MultimapBuilder.hashKeys().arrayListValues().build();
47-
SortedSetMultimap<String, Integer> b = MultimapBuilder.linkedHashKeys().treeSetValues().build();
48-
SetMultimap<String, Integer> c =
46+
ListMultimap<String, Integer> unusedA = MultimapBuilder.hashKeys().arrayListValues().build();
47+
SortedSetMultimap<String, Integer> unusedB =
48+
MultimapBuilder.linkedHashKeys().treeSetValues().build();
49+
SetMultimap<String, Integer> unusedC =
4950
MultimapBuilder.treeKeys(String.CASE_INSENSITIVE_ORDER).hashSetValues().build();
5051
}
5152

5253
public void testGenerics_gwtCompatible() {
53-
ListMultimap<String, Integer> a =
54+
ListMultimap<String, Integer> unusedA =
5455
MultimapBuilder.hashKeys().arrayListValues().<String, Integer>build();
55-
SortedSetMultimap<String, Integer> b =
56+
SortedSetMultimap<String, Integer> unusedB =
5657
rawtypeToWildcard(MultimapBuilder.linkedHashKeys().treeSetValues())
5758
.<String, Integer>build();
58-
SetMultimap<String, Integer> c =
59+
SetMultimap<String, Integer> unusedC =
5960
MultimapBuilder.treeKeys(String.CASE_INSENSITIVE_ORDER)
6061
.hashSetValues()
6162
.<String, Integer>build();

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

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import com.google.common.annotations.GwtIncompatible;
3131
import com.google.common.base.Ascii;
3232
import com.google.common.base.Function;
33-
import com.google.common.base.Predicate;
3433
import com.google.common.base.Predicates;
3534
import com.google.common.base.Supplier;
3635
import com.google.common.collect.Maps.EntryTransformer;
@@ -215,22 +214,6 @@ public List<Entry<String, Integer>> create(Object... elements) {
215214
}
216215
}
217216

218-
private static final Predicate<Entry<Integer, String>> FILTER_GET_PREDICATE =
219-
new Predicate<Entry<Integer, String>>() {
220-
@Override
221-
public boolean apply(Entry<Integer, String> entry) {
222-
return !"badvalue".equals(entry.getValue()) && 55556 != entry.getKey();
223-
}
224-
};
225-
226-
private static final Predicate<Entry<String, Integer>> FILTER_KEYSET_PREDICATE =
227-
new Predicate<Entry<String, Integer>>() {
228-
@Override
229-
public boolean apply(Entry<String, Integer> entry) {
230-
return !"badkey".equals(entry.getKey()) && 55556 != entry.getValue();
231-
}
232-
};
233-
234217
public static Test suite() {
235218
TestSuite suite = new TestSuite();
236219

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

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -326,37 +326,37 @@ public void testCompound_instance_generics() {
326326
Ordering<Integer> integers = Ordering.explicit(1);
327327

328328
// Like by like equals like
329-
Ordering<Number> a = numbers.compound(numbers);
329+
Ordering<Number> unusedA = numbers.compound(numbers);
330330

331331
// The compound takes the more specific type of the two, regardless of order
332332

333-
Ordering<Number> b = numbers.compound(objects);
334-
Ordering<Number> c = objects.compound(numbers);
333+
Ordering<Number> unusedB = numbers.compound(objects);
334+
Ordering<Number> unusedC = objects.compound(numbers);
335335

336-
Ordering<Integer> d = numbers.compound(integers);
337-
Ordering<Integer> e = integers.compound(numbers);
336+
Ordering<Integer> unusedD = numbers.compound(integers);
337+
Ordering<Integer> unusedE = integers.compound(numbers);
338338

339339
// This works with three levels too (IDEA falsely reports errors as noted
340340
// below. Both javac and eclipse handle these cases correctly.)
341341

342-
Ordering<Number> f = numbers.compound(objects).compound(objects); // bad IDEA
343-
Ordering<Number> g = objects.compound(numbers).compound(objects);
344-
Ordering<Number> h = objects.compound(objects).compound(numbers);
342+
Ordering<Number> unusedF = numbers.compound(objects).compound(objects); // bad IDEA
343+
Ordering<Number> unusedG = objects.compound(numbers).compound(objects);
344+
Ordering<Number> unusedH = objects.compound(objects).compound(numbers);
345345

346-
Ordering<Number> i = numbers.compound(objects.compound(objects));
347-
Ordering<Number> j = objects.compound(numbers.compound(objects)); // bad IDEA
348-
Ordering<Number> k = objects.compound(objects.compound(numbers));
346+
Ordering<Number> unusedI = numbers.compound(objects.compound(objects));
347+
Ordering<Number> unusedJ = objects.compound(numbers.compound(objects)); // bad IDEA
348+
Ordering<Number> unusedK = objects.compound(objects.compound(numbers));
349349

350350
// You can also arbitrarily assign a more restricted type - not an intended
351351
// feature, exactly, but unavoidable (I think) and harmless
352-
Ordering<Integer> l = objects.compound(numbers);
352+
Ordering<Integer> unusedL = objects.compound(numbers);
353353

354354
// This correctly doesn't work:
355-
// Ordering<Object> m = numbers.compound(objects);
355+
// Ordering<Object> unusedM = numbers.compound(objects);
356356

357357
// Sadly, the following works in javac 1.6, but at least it fails for
358358
// eclipse, and is *correctly* highlighted red in IDEA.
359-
// Ordering<Object> n = objects.compound(numbers);
359+
// Ordering<Object> unusedN = objects.compound(numbers);
360360
}
361361

362362
public void testReverse() {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,7 @@ public void testEquals() {
613613

614614
@GwtIncompatible // TODO(b/148207871): Restore once Eclipse compiler no longer flakes for this.
615615
public void testLegacyComparable() {
616-
Range<LegacyComparable> range = Range.closed(LegacyComparable.X, LegacyComparable.Y);
616+
Range<LegacyComparable> unused = Range.closed(LegacyComparable.X, LegacyComparable.Y);
617617
}
618618

619619
private static final DiscreteDomain<Integer> UNBOUNDED_DOMAIN =

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ protected <K, V> BiMap<K, V> create() {
7979
public static final class SynchronizedHashBiMapGenerator extends TestStringBiMapGenerator {
8080
@Override
8181
protected BiMap<String, String> create(Entry<String, String>[] entries) {
82-
Object mutex = new Object();
8382
BiMap<String, String> result = HashBiMap.create();
8483
for (Entry<String, String> entry : entries) {
8584
checkArgument(!result.containsKey(entry.getKey()));

android/guava-tests/test/com/google/common/eventbus/PackageSanityTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ private static class DummySubscriber {
4141
private final EventBus eventBus = new EventBus();
4242

4343
@Subscribe
44-
public void handle(@Nullable Object anything) {}
44+
public void handle(@Nullable Object unused) {}
4545

4646
Subscriber toSubscriber() throws Exception {
4747
return Subscriber.create(eventBus, this, subscriberMethod());

android/guava-tests/test/com/google/common/graph/AbstractStandardDirectedGraphTest.java

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ public void nodes_checkReturnedSetMutability() {
3636
assume().that(graphIsMutable()).isTrue();
3737

3838
Set<Integer> nodes = graph.nodes();
39-
UnsupportedOperationException e =
40-
assertThrows(UnsupportedOperationException.class, () -> nodes.add(N2));
39+
assertThrows(UnsupportedOperationException.class, () -> nodes.add(N2));
4140
addNode(N1);
4241
assertThat(graph.nodes()).containsExactlyElementsIn(nodes);
4342
}
@@ -49,8 +48,7 @@ public void adjacentNodes_checkReturnedSetMutability() {
4948

5049
addNode(N1);
5150
Set<Integer> adjacentNodes = graph.adjacentNodes(N1);
52-
UnsupportedOperationException e =
53-
assertThrows(UnsupportedOperationException.class, () -> adjacentNodes.add(N2));
51+
assertThrows(UnsupportedOperationException.class, () -> adjacentNodes.add(N2));
5452
putEdge(N1, N2);
5553
assertThat(graph.adjacentNodes(N1)).containsExactlyElementsIn(adjacentNodes);
5654
}
@@ -62,8 +60,7 @@ public void predecessors_checkReturnedSetMutability() {
6260

6361
addNode(N2);
6462
Set<Integer> predecessors = graph.predecessors(N2);
65-
UnsupportedOperationException e =
66-
assertThrows(UnsupportedOperationException.class, () -> predecessors.add(N1));
63+
assertThrows(UnsupportedOperationException.class, () -> predecessors.add(N1));
6764
putEdge(N1, N2);
6865
assertThat(graph.predecessors(N2)).containsExactlyElementsIn(predecessors);
6966
}
@@ -75,8 +72,7 @@ public void successors_checkReturnedSetMutability() {
7572

7673
addNode(N1);
7774
Set<Integer> successors = graph.successors(N1);
78-
UnsupportedOperationException e =
79-
assertThrows(UnsupportedOperationException.class, () -> successors.add(N2));
75+
assertThrows(UnsupportedOperationException.class, () -> successors.add(N2));
8076
putEdge(N1, N2);
8177
assertThat(successors).containsExactlyElementsIn(graph.successors(N1));
8278
}
@@ -88,10 +84,8 @@ public void incidentEdges_checkReturnedSetMutability() {
8884

8985
addNode(N1);
9086
Set<EndpointPair<Integer>> incidentEdges = graph.incidentEdges(N1);
91-
UnsupportedOperationException e =
92-
assertThrows(
93-
UnsupportedOperationException.class,
94-
() -> incidentEdges.add(EndpointPair.ordered(N1, N2)));
87+
assertThrows(
88+
UnsupportedOperationException.class, () -> incidentEdges.add(EndpointPair.ordered(N1, N2)));
9589
putEdge(N1, N2);
9690
assertThat(incidentEdges).containsExactlyElementsIn(graph.incidentEdges(N1));
9791
}

0 commit comments

Comments
 (0)