Skip to content

Commit

Permalink
Address some UnusedVariable warnings.
Browse files Browse the repository at this point in the history
And perform a few tiny other cleanups.

RELNOTES=n/a
PiperOrigin-RevId: 648782393
  • Loading branch information
cpovirk authored and Google Java Core Libraries committed Jul 2, 2024
1 parent 9ba5fea commit 3618043
Show file tree
Hide file tree
Showing 50 changed files with 174 additions and 288 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,9 @@ public <V> ListenableScheduledFuture<V> schedule(
return new ImmediateScheduledFuture<>(delegateFuture);
}

private static class ImmediateScheduledFuture<V> extends SimpleForwardingListenableFuture<V>
private static final class ImmediateScheduledFuture<V> extends SimpleForwardingListenableFuture<V>
implements ListenableScheduledFuture<V> {
private ExecutionException exception;

protected ImmediateScheduledFuture(ListenableFuture<V> future) {
ImmediateScheduledFuture(ListenableFuture<V> future) {
super(future);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,43 +44,43 @@ public class GcFinalizationTest extends TestCase {

public void testAwait_CountDownLatch() {
final CountDownLatch latch = new CountDownLatch(1);
Object x =
Object unused =
new Object() {
@Override
protected void finalize() {
latch.countDown();
}
};
x = null; // Hint to the JIT that x is unreachable
unused = null; // Hint to the JIT that unused is unreachable
GcFinalization.await(latch);
assertEquals(0, latch.getCount());
}

public void testAwaitDone_Future() {
final SettableFuture<@Nullable Void> future = SettableFuture.create();
Object x =
Object unused =
new Object() {
@Override
protected void finalize() {
future.set(null);
}
};
x = null; // Hint to the JIT that x is unreachable
unused = null; // Hint to the JIT that unused is unreachable
GcFinalization.awaitDone(future);
assertTrue(future.isDone());
assertFalse(future.isCancelled());
}

public void testAwaitDone_Future_Cancel() {
final SettableFuture<@Nullable Void> future = SettableFuture.create();
Object x =
Object unused =
new Object() {
@Override
protected void finalize() {
future.cancel(false);
}
};
x = null; // Hint to the JIT that x is unreachable
unused = null; // Hint to the JIT that unused is unreachable
GcFinalization.awaitDone(future);
assertTrue(future.isDone());
assertTrue(future.isCancelled());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ void setUp() {
if (size == Size.SMALL) {
BitSet tmp = new BitSet();
matcher.setBits(tmp);
int matchedCharCount = tmp.cardinality();
this.matcher = SmallCharMatcher.from(tmp, "");
}
this.string = checkString(length, percent, config.matchingChars, new Random(), forceSlow, web);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,24 @@ void setUp() {
}

@Benchmark
void charSplitter(int reps) {
int charSplitter(int reps) {
int total = 0;

for (int i = 0; i < reps; i++) {
total += Iterables.size(CHAR_SPLITTER.split(input));
}

return total;
}

@Benchmark
void stringSplitter(int reps) {
int stringSplitter(int reps) {
int total = 0;

for (int i = 0; i < reps; i++) {
total += Iterables.size(STRING_SPLITTER.split(input));
}

return total;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ void setUp() {
int sizeRemaining = size;

// TODO(kevinb): generate better test contents for multisets
for (int i = 0; sizeRemaining > 0; i++) {
while (sizeRemaining > 0) {
// The JVM will return interned values for small ints.
Integer value = random.nextInt(1000) + 128;
int count = Math.min(random.nextInt(10) + 1, sizeRemaining);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ public void testCompositionWildcard() {

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

Function<String, String> japaneseToSpanish =
Function<String, String> unusedJapaneseToSpanish =
Functions.compose(numberToSpanish, japaneseToInteger);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1959,7 +1959,7 @@ public void testRemoveEntry() {
table.set(0, entry);
segment.count = 1;
assertTrue(segment.removeEntry(entry, hash, RemovalCause.COLLECTED));
assertNotificationEnqueued(map, key, value, hash);
assertNotificationEnqueued(map, key, value);
assertTrue(map.removalNotificationQueue.isEmpty());
assertFalse(segment.accessQueue.contains(entry));
assertFalse(segment.writeQueue.contains(entry));
Expand Down Expand Up @@ -2068,8 +2068,7 @@ public void testRemoveComputingValue() {
assertTrue(segment.removeLoadingValue(key, hash, valueRef));
}

private static <K, V> void assertNotificationEnqueued(
LocalCache<K, V> map, K key, V value, int hash) {
private static <K, V> void assertNotificationEnqueued(LocalCache<K, V> map, K key, V value) {
RemovalNotification<K, V> notification = map.removalNotificationQueue.poll();
assertSame(key, notification.getKey());
assertSame(value, notification.getValue());
Expand Down Expand Up @@ -2595,7 +2594,7 @@ public void testNullParameters() throws Exception {
NullPointerTester tester = new NullPointerTester();
tester.testAllPublicInstanceMethods(makeLocalCache(createCacheBuilder()));
CacheLoader<Object, Object> loader = identityLoader();
tester.testAllPublicInstanceMethods(makeLocalCache(createCacheBuilder()));
tester.testAllPublicInstanceMethods(makeLocalCache(createCacheBuilder(), loader));
}

public void testSerializationProxyLoading() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ public void testStats() {
assertEquals(3.0 / 4, stats.missRate());
assertEquals(3, stats.loadCount());
assertTrue(stats.totalLoadTime() >= totalLoadTime);
totalLoadTime = stats.totalLoadTime();
assertTrue(stats.averageLoadPenalty() >= 0.0);
assertEquals(1, stats.evictionCount());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public class PopulatedCachesTest extends TestCase {
public void testSize_populated() {
for (LoadingCache<Object, Object> cache : caches()) {
// don't let the entries get GCed
List<Entry<Object, Object>> warmed = warmUp(cache);
List<Entry<Object, Object>> unused = warmUp(cache);
assertEquals(WARMUP_SIZE, cache.size());
assertMapSize(cache.asMap(), WARMUP_SIZE);
checkValidState(cache);
Expand Down Expand Up @@ -125,7 +125,7 @@ public void testPutIfAbsent_populated() {
public void testPutAll_populated() {
for (LoadingCache<Object, Object> cache : caches()) {
// don't let the entries get GCed
List<Entry<Object, Object>> warmed = warmUp(cache);
List<Entry<Object, Object>> unused = warmUp(cache);
Object newKey = new Object();
Object newValue = new Object();
cache.asMap().putAll(ImmutableMap.of(newKey, newValue));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -409,11 +409,7 @@ public void testExhaustive() {
}

if (anyOverlaps) {
assertThrows(
IllegalArgumentException.class,
() -> {
RangeSet<Integer> copy = ImmutableRangeSet.copyOf(subset);
});
assertThrows(IllegalArgumentException.class, () -> ImmutableRangeSet.copyOf(subset));
} else {
RangeSet<Integer> copy = ImmutableRangeSet.copyOf(subset);
assertEquals(mutable, copy);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -826,20 +826,20 @@ public int compareTo(SelfComparableExample o) {
}

public void testBuilderGenerics_SelfComparable() {
ImmutableSortedMap.Builder<SelfComparableExample, Object> natural =
ImmutableSortedMap.Builder<SelfComparableExample, Object> unusedNatural =
ImmutableSortedMap.naturalOrder();

ImmutableSortedMap.Builder<SelfComparableExample, Object> reverse =
ImmutableSortedMap.Builder<SelfComparableExample, Object> unusedReverse =
ImmutableSortedMap.reverseOrder();
}

private static class SuperComparableExample extends SelfComparableExample {}

public void testBuilderGenerics_SuperComparable() {
ImmutableSortedMap.Builder<SuperComparableExample, Object> natural =
ImmutableSortedMap.Builder<SuperComparableExample, Object> unusedNatural =
ImmutableSortedMap.naturalOrder();

ImmutableSortedMap.Builder<SuperComparableExample, Object> reverse =
ImmutableSortedMap.Builder<SuperComparableExample, Object> unusedReverse =
ImmutableSortedMap.reverseOrder();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,20 @@ public class MultimapBuilderTest extends TestCase {
@J2ktIncompatible
@GwtIncompatible // doesn't build without explicit type parameters on build() methods
public void testGenerics() {
ListMultimap<String, Integer> a = MultimapBuilder.hashKeys().arrayListValues().build();
SortedSetMultimap<String, Integer> b = MultimapBuilder.linkedHashKeys().treeSetValues().build();
SetMultimap<String, Integer> c =
ListMultimap<String, Integer> unusedA = MultimapBuilder.hashKeys().arrayListValues().build();
SortedSetMultimap<String, Integer> unusedB =
MultimapBuilder.linkedHashKeys().treeSetValues().build();
SetMultimap<String, Integer> unusedC =
MultimapBuilder.treeKeys(String.CASE_INSENSITIVE_ORDER).hashSetValues().build();
}

public void testGenerics_gwtCompatible() {
ListMultimap<String, Integer> a =
ListMultimap<String, Integer> unusedA =
MultimapBuilder.hashKeys().arrayListValues().<String, Integer>build();
SortedSetMultimap<String, Integer> b =
SortedSetMultimap<String, Integer> unusedB =
rawtypeToWildcard(MultimapBuilder.linkedHashKeys().treeSetValues())
.<String, Integer>build();
SetMultimap<String, Integer> c =
SetMultimap<String, Integer> unusedC =
MultimapBuilder.treeKeys(String.CASE_INSENSITIVE_ORDER)
.hashSetValues()
.<String, Integer>build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import com.google.common.annotations.GwtIncompatible;
import com.google.common.base.Ascii;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import com.google.common.base.Supplier;
import com.google.common.collect.Maps.EntryTransformer;
Expand Down Expand Up @@ -215,22 +214,6 @@ public List<Entry<String, Integer>> create(Object... elements) {
}
}

private static final Predicate<Entry<Integer, String>> FILTER_GET_PREDICATE =
new Predicate<Entry<Integer, String>>() {
@Override
public boolean apply(Entry<Integer, String> entry) {
return !"badvalue".equals(entry.getValue()) && 55556 != entry.getKey();
}
};

private static final Predicate<Entry<String, Integer>> FILTER_KEYSET_PREDICATE =
new Predicate<Entry<String, Integer>>() {
@Override
public boolean apply(Entry<String, Integer> entry) {
return !"badkey".equals(entry.getKey()) && 55556 != entry.getValue();
}
};

public static Test suite() {
TestSuite suite = new TestSuite();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,37 +326,37 @@ public void testCompound_instance_generics() {
Ordering<Integer> integers = Ordering.explicit(1);

// Like by like equals like
Ordering<Number> a = numbers.compound(numbers);
Ordering<Number> unusedA = numbers.compound(numbers);

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

Ordering<Number> b = numbers.compound(objects);
Ordering<Number> c = objects.compound(numbers);
Ordering<Number> unusedB = numbers.compound(objects);
Ordering<Number> unusedC = objects.compound(numbers);

Ordering<Integer> d = numbers.compound(integers);
Ordering<Integer> e = integers.compound(numbers);
Ordering<Integer> unusedD = numbers.compound(integers);
Ordering<Integer> unusedE = integers.compound(numbers);

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

Ordering<Number> f = numbers.compound(objects).compound(objects); // bad IDEA
Ordering<Number> g = objects.compound(numbers).compound(objects);
Ordering<Number> h = objects.compound(objects).compound(numbers);
Ordering<Number> unusedF = numbers.compound(objects).compound(objects); // bad IDEA
Ordering<Number> unusedG = objects.compound(numbers).compound(objects);
Ordering<Number> unusedH = objects.compound(objects).compound(numbers);

Ordering<Number> i = numbers.compound(objects.compound(objects));
Ordering<Number> j = objects.compound(numbers.compound(objects)); // bad IDEA
Ordering<Number> k = objects.compound(objects.compound(numbers));
Ordering<Number> unusedI = numbers.compound(objects.compound(objects));
Ordering<Number> unusedJ = objects.compound(numbers.compound(objects)); // bad IDEA
Ordering<Number> unusedK = objects.compound(objects.compound(numbers));

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

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

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

public void testReverse() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@ public void testEquals() {

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

private static final DiscreteDomain<Integer> UNBOUNDED_DOMAIN =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ protected <K, V> BiMap<K, V> create() {
public static final class SynchronizedHashBiMapGenerator extends TestStringBiMapGenerator {
@Override
protected BiMap<String, String> create(Entry<String, String>[] entries) {
Object mutex = new Object();
BiMap<String, String> result = HashBiMap.create();
for (Entry<String, String> entry : entries) {
checkArgument(!result.containsKey(entry.getKey()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ private static class DummySubscriber {
private final EventBus eventBus = new EventBus();

@Subscribe
public void handle(@Nullable Object anything) {}
public void handle(@Nullable Object unused) {}

Subscriber toSubscriber() throws Exception {
return Subscriber.create(eventBus, this, subscriberMethod());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ public void nodes_checkReturnedSetMutability() {
assume().that(graphIsMutable()).isTrue();

Set<Integer> nodes = graph.nodes();
UnsupportedOperationException e =
assertThrows(UnsupportedOperationException.class, () -> nodes.add(N2));
assertThrows(UnsupportedOperationException.class, () -> nodes.add(N2));
addNode(N1);
assertThat(graph.nodes()).containsExactlyElementsIn(nodes);
}
Expand All @@ -49,8 +48,7 @@ public void adjacentNodes_checkReturnedSetMutability() {

addNode(N1);
Set<Integer> adjacentNodes = graph.adjacentNodes(N1);
UnsupportedOperationException e =
assertThrows(UnsupportedOperationException.class, () -> adjacentNodes.add(N2));
assertThrows(UnsupportedOperationException.class, () -> adjacentNodes.add(N2));
putEdge(N1, N2);
assertThat(graph.adjacentNodes(N1)).containsExactlyElementsIn(adjacentNodes);
}
Expand All @@ -62,8 +60,7 @@ public void predecessors_checkReturnedSetMutability() {

addNode(N2);
Set<Integer> predecessors = graph.predecessors(N2);
UnsupportedOperationException e =
assertThrows(UnsupportedOperationException.class, () -> predecessors.add(N1));
assertThrows(UnsupportedOperationException.class, () -> predecessors.add(N1));
putEdge(N1, N2);
assertThat(graph.predecessors(N2)).containsExactlyElementsIn(predecessors);
}
Expand All @@ -75,8 +72,7 @@ public void successors_checkReturnedSetMutability() {

addNode(N1);
Set<Integer> successors = graph.successors(N1);
UnsupportedOperationException e =
assertThrows(UnsupportedOperationException.class, () -> successors.add(N2));
assertThrows(UnsupportedOperationException.class, () -> successors.add(N2));
putEdge(N1, N2);
assertThat(successors).containsExactlyElementsIn(graph.successors(N1));
}
Expand All @@ -88,10 +84,8 @@ public void incidentEdges_checkReturnedSetMutability() {

addNode(N1);
Set<EndpointPair<Integer>> incidentEdges = graph.incidentEdges(N1);
UnsupportedOperationException e =
assertThrows(
UnsupportedOperationException.class,
() -> incidentEdges.add(EndpointPair.ordered(N1, N2)));
assertThrows(
UnsupportedOperationException.class, () -> incidentEdges.add(EndpointPair.ordered(N1, N2)));
putEdge(N1, N2);
assertThat(incidentEdges).containsExactlyElementsIn(graph.incidentEdges(N1));
}
Expand Down
Loading

0 comments on commit 3618043

Please sign in to comment.