Skip to content

Commit

Permalink
Work around or suppress forthcoming nullness errors.
Browse files Browse the repository at this point in the history
This CL also provides a little more progress toward #3679: One of the workarounds involves removing a call to the long-obsolete `Iterators.cast`, and I went ahead and removed the method itself, too.

RELNOTES=n/a
PiperOrigin-RevId: 584417248
  • Loading branch information
cpovirk authored and Google Java Core Libraries committed Nov 21, 2023
1 parent 3856cac commit e5cc39c
Show file tree
Hide file tree
Showing 9 changed files with 11 additions and 20 deletions.
6 changes: 0 additions & 6 deletions android/guava/src/com/google/common/collect/Iterators.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
import java.util.Enumeration;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import java.util.NoSuchElementException;
import java.util.PriorityQueue;
import java.util.Queue;
Expand Down Expand Up @@ -1444,9 +1443,4 @@ public void remove() {
toRemove = null;
}
}

/** Used to avoid http://bugs.sun.com/view_bug.do?bug_id=6558557 */
static <T extends @Nullable Object> ListIterator<T> cast(Iterator<T> iterator) {
return (ListIterator<T>) iterator;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ final class TableCollectors {
java.util.function.Function<? super T, ? extends C> columnFunction,
java.util.function.Function<? super T, ? extends V> valueFunction,
java.util.function.Supplier<I> tableSupplier) {
return toTable(
return TableCollectors.<T, R, C, V, I>toTable(
rowFunction,
columnFunction,
valueFunction,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ abstract class TransformedListIterator<F extends @Nullable Object, T extends @Nu
}

private ListIterator<? extends F> backingIterator() {
return Iterators.cast(backingIterator);
return (ListIterator<? extends F>) backingIterator;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ A result(Collector<T, A, R> collector, Iterable<T> inputs) {
*/
@SafeVarargs
@CanIgnoreReturnValue
@SuppressWarnings("nullness") // TODO(cpovirk): Remove after we fix whatever the bug is.
public final CollectorTester<T, A, R> expectCollects(R expectedResult, T... inputs) {
List<T> list = Arrays.asList(inputs);
doExpectCollects(expectedResult, list);
Expand Down
6 changes: 0 additions & 6 deletions guava/src/com/google/common/collect/Iterators.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
import java.util.Enumeration;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import java.util.NoSuchElementException;
import java.util.PriorityQueue;
import java.util.Queue;
Expand Down Expand Up @@ -1444,9 +1443,4 @@ public void remove() {
toRemove = null;
}
}

/** Used to avoid http://bugs.sun.com/view_bug.do?bug_id=6558557 */
static <T extends @Nullable Object> ListIterator<T> cast(Iterator<T> iterator) {
return (ListIterator<T>) iterator;
}
}
5 changes: 3 additions & 2 deletions guava/src/com/google/common/collect/Multimaps.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ private Multimaps() {}
java.util.function.Function<? super T, ? extends K> keyFunction,
java.util.function.Function<? super T, ? extends V> valueFunction,
java.util.function.Supplier<M> multimapSupplier) {
return CollectCollectors.toMultimap(keyFunction, valueFunction, multimapSupplier);
return CollectCollectors.<T, K, V, M>toMultimap(keyFunction, valueFunction, multimapSupplier);
}

/**
Expand Down Expand Up @@ -167,7 +167,8 @@ private Multimaps() {}
java.util.function.Function<? super T, ? extends K> keyFunction,
java.util.function.Function<? super T, ? extends Stream<? extends V>> valueFunction,
java.util.function.Supplier<M> multimapSupplier) {
return CollectCollectors.flatteningToMultimap(keyFunction, valueFunction, multimapSupplier);
return CollectCollectors.<T, K, V, M>flatteningToMultimap(
keyFunction, valueFunction, multimapSupplier);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion guava/src/com/google/common/collect/TableCollectors.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ final class TableCollectors {
java.util.function.Function<? super T, ? extends C> columnFunction,
java.util.function.Function<? super T, ? extends V> valueFunction,
java.util.function.Supplier<I> tableSupplier) {
return toTable(
return TableCollectors.<T, R, C, V, I>toTable(
rowFunction,
columnFunction,
valueFunction,
Expand Down
5 changes: 3 additions & 2 deletions guava/src/com/google/common/collect/Tables.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ private Tables() {}
java.util.function.Function<? super T, ? extends C> columnFunction,
java.util.function.Function<? super T, ? extends V> valueFunction,
java.util.function.Supplier<I> tableSupplier) {
return TableCollectors.toTable(rowFunction, columnFunction, valueFunction, tableSupplier);
return TableCollectors.<T, R, C, V, I>toTable(
rowFunction, columnFunction, valueFunction, tableSupplier);
}

/**
Expand Down Expand Up @@ -106,7 +107,7 @@ private Tables() {}
java.util.function.Function<? super T, ? extends V> valueFunction,
BinaryOperator<V> mergeFunction,
java.util.function.Supplier<I> tableSupplier) {
return TableCollectors.toTable(
return TableCollectors.<T, R, C, V, I>toTable(
rowFunction, columnFunction, valueFunction, mergeFunction, tableSupplier);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ abstract class TransformedListIterator<F extends @Nullable Object, T extends @Nu
}

private ListIterator<? extends F> backingIterator() {
return Iterators.cast(backingIterator);
return (ListIterator<? extends F>) backingIterator;
}

@Override
Expand Down

0 comments on commit e5cc39c

Please sign in to comment.