Skip to content

Commit

Permalink
Disable Java7ApiChecker for our *tests*, removing most of its suppr…
Browse files Browse the repository at this point in the history
…essions and also most `AndroidJdkLibsChecker` suppressions.

(`AndroidJdkLibsChecker` (albeit in "desugaring mode") and Animal Sniffer will continue to run.)

It's not clear that `Java7ApiChecker` is useful even for our *prod* code at this point, as discussed in b/336133887. Let's at least start by disabling it for tests, where it's one of the remaining annoyances when adding support for Java 8 APIs to our Android branch.

(The actual immediate motivation for this CL is cl/686562711.)

The _`AndroidJdkLibsChecker`_ suppressions can be removed now that the standard configuration inside Google enables opt-in library desugaring, which signals to `AndroidJdkLibsChecker` not to warn about the methods that we're using. (Again, we still have checking from Animal Sniffer.)

RELNOTES=n/a
PiperOrigin-RevId: 686638643
  • Loading branch information
cpovirk authored and Google Java Core Libraries committed Oct 16, 2024
1 parent 98d5528 commit 702e4b2
Show file tree
Hide file tree
Showing 28 changed files with 43 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ public void testNullPointerExceptions() {
}

@GwtIncompatible // java.time.Duration
@SuppressWarnings("Java7ApiChecker") // guava-android can rely on library desugaring now.
@IgnoreJRERequirement // TODO: b/288085449 - Remove this once we use library-desugaring scents.
public void testAdvance() {
FakeTicker ticker = new FakeTicker();
Expand Down Expand Up @@ -84,7 +83,6 @@ public void testAutoIncrementStep_seconds() {
}

@GwtIncompatible // java.time.Duration
@SuppressWarnings("Java7ApiChecker") // guava-android can rely on library desugaring now.
@IgnoreJRERequirement // TODO: b/288085449 - Remove this once we use library-desugaring scents.
public void testAutoIncrementStep_duration() {
FakeTicker ticker = new FakeTicker().setAutoIncrementStep(Duration.ofMillis(1));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,6 @@ public void testMemoizeWithExpiration_longTimeUnit() throws InterruptedException

@J2ktIncompatible
@GwtIncompatible // Thread.sleep
@SuppressWarnings("Java7ApiChecker") // test of Java 8+ API
public void testMemoizeWithExpiration_duration() throws InterruptedException {
CountingSupplier countingSupplier = new CountingSupplier();

Expand All @@ -252,7 +251,6 @@ public void testMemoizeWithExpiration_longTimeUnitNegative() throws InterruptedE
() -> Suppliers.memoizeWithExpiration(() -> "", -1, TimeUnit.MILLISECONDS));
}

@SuppressWarnings("Java7ApiChecker") // test of Java 8+ API
@J2ktIncompatible // Duration
@GwtIncompatible // Duration
public void testMemoizeWithExpiration_durationNegative() throws InterruptedException {
Expand Down Expand Up @@ -496,7 +494,6 @@ public void testSerialization() {

@J2ktIncompatible
@GwtIncompatible // reflection
@SuppressWarnings("Java7ApiChecker") // includes test of Java 8+ API
public void testSuppliersNullChecks() throws Exception {
new ClassSanityTester()
.setDefault(Duration.class, Duration.ofSeconds(1))
Expand All @@ -507,7 +504,6 @@ public void testSuppliersNullChecks() throws Exception {
@J2ktIncompatible
@GwtIncompatible // reflection
@AndroidIncompatible // TODO(cpovirk): ClassNotFoundException: com.google.common.base.Function
@SuppressWarnings("Java7ApiChecker") // includes test of Java 8+ API
public void testSuppliersSerializable() throws Exception {
new ClassSanityTester()
.setDefault(Duration.class, Duration.ofSeconds(1))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,6 @@ public void testValueStrengthSetTwice() {
}

@GwtIncompatible // Duration
@SuppressWarnings("Java7ApiChecker")
@IgnoreJRERequirement // No more dangerous than wherever the caller got the Duration from
public void testLargeDurationsAreOk() {
Duration threeHundredYears = Duration.ofDays(365 * 300);
Expand All @@ -251,7 +250,6 @@ public void testTimeToLive_negative() {
}

@GwtIncompatible // Duration
@SuppressWarnings("Java7ApiChecker")
public void testTimeToLive_negative_duration() {
CacheBuilder<Object, Object> builder = CacheBuilder.newBuilder();
assertThrows(
Expand All @@ -276,7 +274,6 @@ public void testTimeToLive_setTwice() {
}

@GwtIncompatible // Duration
@SuppressWarnings("Java7ApiChecker")
public void testTimeToLive_setTwice_duration() {
CacheBuilder<Object, Object> builder =
CacheBuilder.newBuilder().expireAfterWrite(Duration.ofHours(1));
Expand All @@ -293,7 +290,6 @@ public void testTimeToIdle_negative() {
}

@GwtIncompatible // Duration
@SuppressWarnings("Java7ApiChecker")
public void testTimeToIdle_negative_duration() {
CacheBuilder<Object, Object> builder = CacheBuilder.newBuilder();
assertThrows(
Expand All @@ -318,14 +314,12 @@ public void testTimeToIdle_setTwice() {
}

@GwtIncompatible // Duration
@SuppressWarnings("Java7ApiChecker")
public void testTimeToIdle_setTwice_duration() {
CacheBuilder<Object, Object> builder =
CacheBuilder.newBuilder().expireAfterAccess(Duration.ofHours(1));
assertThrows(IllegalStateException.class, () -> builder.expireAfterAccess(Duration.ofHours(1)));
}

@SuppressWarnings("Java7ApiChecker")
public void testTimeToIdleAndToLive() {
LoadingCache<?, ?> unused =
CacheBuilder.newBuilder()
Expand All @@ -342,7 +336,6 @@ public void testRefresh_zero() {
}

@GwtIncompatible // Duration
@SuppressWarnings("Java7ApiChecker")
public void testRefresh_zero_duration() {
CacheBuilder<Object, Object> builder = CacheBuilder.newBuilder();
assertThrows(IllegalArgumentException.class, () -> builder.refreshAfterWrite(Duration.ZERO));
Expand All @@ -356,7 +349,6 @@ public void testRefresh_setTwice() {
}

@GwtIncompatible // Duration
@SuppressWarnings("Java7ApiChecker")
public void testRefresh_setTwice_duration() {
CacheBuilder<Object, Object> builder =
CacheBuilder.newBuilder().refreshAfterWrite(Duration.ofHours(1));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
/** Collectors utilities for {@code common.collect} internals. */
@GwtCompatible
@ElementTypesAreNonnullByDefault
@SuppressWarnings({"AndroidJdkLibsChecker", "Java7ApiChecker"})
@SuppressWarnings("Java7ApiChecker")
@IgnoreJRERequirement // used only from APIs with Java 8 types in them
// (not used publicly by guava-android as of this writing, but we include it in the jar as a test)
final class CollectCollectors {
Expand Down
4 changes: 2 additions & 2 deletions android/guava/src/com/google/common/collect/Comparators.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ private Comparators() {}
* @throws IllegalArgumentException if {@code k < 0}
* @since 33.2.0 (available since 22.0 in guava-jre)
*/
@SuppressWarnings({"AndroidJdkLibsChecker", "Java7ApiChecker"})
@SuppressWarnings("Java7ApiChecker")
@IgnoreJRERequirement // Users will use this only if they're already using streams.
public static <T extends @Nullable Object> Collector<T, ?, List<T>> least(
int k, Comparator<? super T> comparator) {
Expand Down Expand Up @@ -163,7 +163,7 @@ private Comparators() {}
* @throws IllegalArgumentException if {@code k < 0}
* @since 33.2.0 (available since 22.0 in guava-jre)
*/
@SuppressWarnings({"AndroidJdkLibsChecker", "Java7ApiChecker"})
@SuppressWarnings("Java7ApiChecker")
@IgnoreJRERequirement // Users will use this only if they're already using streams.
public static <T extends @Nullable Object> Collector<T, ?, List<T>> greatest(
int k, Comparator<? super T> comparator) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public abstract class ImmutableBiMap<K, V> extends ImmutableMap<K, V> implements
*
* @since 33.2.0 (available since 21.0 in guava-jre)
*/
@SuppressWarnings({"AndroidJdkLibsChecker", "Java7ApiChecker"})
@SuppressWarnings("Java7ApiChecker")
@IgnoreJRERequirement // Users will use this only if they're already using streams.
public static <T extends @Nullable Object, K, V>
Collector<T, ?, ImmutableBiMap<K, V>> toImmutableBiMap(
Expand Down Expand Up @@ -628,7 +628,7 @@ private void readObject(ObjectInputStream stream) throws InvalidObjectException
*/
@Deprecated
@DoNotCall("Use toImmutableBiMap")
@SuppressWarnings({"AndroidJdkLibsChecker", "Java7ApiChecker"})
@SuppressWarnings("Java7ApiChecker")
@IgnoreJRERequirement // Users will use this only if they're already using streams.
public static <T extends @Nullable Object, K, V>
Collector<T, ?, ImmutableMap<K, V>> toImmutableMap(
Expand All @@ -648,7 +648,7 @@ private void readObject(ObjectInputStream stream) throws InvalidObjectException
*/
@Deprecated
@DoNotCall("Use toImmutableBiMap")
@SuppressWarnings({"AndroidJdkLibsChecker", "Java7ApiChecker"})
@SuppressWarnings("Java7ApiChecker")
@IgnoreJRERequirement // Users will use this only if they're already using streams.
public static <T extends @Nullable Object, K, V>
Collector<T, ?, ImmutableMap<K, V>> toImmutableMap(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public abstract class ImmutableCollection<E> extends AbstractCollection<E> imple
* These are properties of the collection as a whole; SIZED and SUBSIZED are more properties of
* the spliterator implementation.
*/
@SuppressWarnings({"AndroidJdkLibsChecker", "Java7ApiChecker"})
@SuppressWarnings("Java7ApiChecker")
// @IgnoreJRERequirement is not necessary because this compiles down to a constant.
// (which is fortunate because Animal Sniffer doesn't look for @IgnoreJRERequirement on fields)
static final int SPLITERATOR_CHARACTERISTICS =
Expand All @@ -191,7 +191,7 @@ public abstract class ImmutableCollection<E> extends AbstractCollection<E> imple
public abstract UnmodifiableIterator<E> iterator();

@Override
@SuppressWarnings({"AndroidJdkLibsChecker", "Java7ApiChecker"})
@SuppressWarnings("Java7ApiChecker")
@IgnoreJRERequirement // used only from APIs with Java 8 types in them
// (not used within guava-android as of this writing, but we include it in the jar as a test)
public Spliterator<E> spliterator() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public abstract class ImmutableList<E> extends ImmutableCollection<E>
*
* @since 33.2.0 (available since 21.0 in guava-jre)
*/
@SuppressWarnings({"AndroidJdkLibsChecker", "Java7ApiChecker"})
@SuppressWarnings("Java7ApiChecker")
@IgnoreJRERequirement // Users will use this only if they're already using streams.
public static <E> Collector<E, ?, ImmutableList<E>> toImmutableList() {
return CollectCollectors.toImmutableList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public class ImmutableListMultimap<K, V> extends ImmutableMultimap<K, V>
*
* @since 33.2.0 (available since 21.0 in guava-jre)
*/
@SuppressWarnings({"AndroidJdkLibsChecker", "Java7ApiChecker"})
@SuppressWarnings("Java7ApiChecker")
@IgnoreJRERequirement // Users will use this only if they're already using streams.
public static <T extends @Nullable Object, K, V>
Collector<T, ?, ImmutableListMultimap<K, V>> toImmutableListMultimap(
Expand Down Expand Up @@ -122,7 +122,7 @@ public class ImmutableListMultimap<K, V> extends ImmutableMultimap<K, V>
*
* @since 33.2.0 (available since 21.0 in guava-jre)
*/
@SuppressWarnings({"AndroidJdkLibsChecker", "Java7ApiChecker"})
@SuppressWarnings("Java7ApiChecker")
@IgnoreJRERequirement // Users will use this only if they're already using streams.
public static <T extends @Nullable Object, K, V>
Collector<T, ?, ImmutableListMultimap<K, V>> flatteningToImmutableListMultimap(
Expand Down
4 changes: 2 additions & 2 deletions android/guava/src/com/google/common/collect/ImmutableMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public abstract class ImmutableMap<K, V> implements Map<K, V>, Serializable {
*
* @since 33.2.0 (available since 21.0 in guava-jre)
*/
@SuppressWarnings({"AndroidJdkLibsChecker", "Java7ApiChecker"})
@SuppressWarnings("Java7ApiChecker")
@IgnoreJRERequirement // Users will use this only if they're already using streams.
public static <T extends @Nullable Object, K, V>
Collector<T, ?, ImmutableMap<K, V>> toImmutableMap(
Expand All @@ -104,7 +104,7 @@ public abstract class ImmutableMap<K, V> implements Map<K, V>, Serializable {
*
* @since 33.2.0 (available since 21.0 in guava-jre)
*/
@SuppressWarnings({"AndroidJdkLibsChecker", "Java7ApiChecker"})
@SuppressWarnings("Java7ApiChecker")
@IgnoreJRERequirement // Users will use this only if they're already using streams.
public static <T extends @Nullable Object, K, V>
Collector<T, ?, ImmutableMap<K, V>> toImmutableMap(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public abstract class ImmutableMultiset<E> extends ImmutableMultisetGwtSerializa
*
* @since 33.2.0 (available since 21.0 in guava-jre)
*/
@SuppressWarnings({"AndroidJdkLibsChecker", "Java7ApiChecker"})
@SuppressWarnings("Java7ApiChecker")
@IgnoreJRERequirement // Users will use this only if they're already using streams.
public static <E> Collector<E, ?, ImmutableMultiset<E>> toImmutableMultiset() {
return CollectCollectors.toImmutableMultiset(Function.identity(), e -> 1);
Expand All @@ -84,7 +84,7 @@ public abstract class ImmutableMultiset<E> extends ImmutableMultisetGwtSerializa
*
* @since 33.2.0 (available since 22.0 in guava-jre)
*/
@SuppressWarnings({"AndroidJdkLibsChecker", "Java7ApiChecker"})
@SuppressWarnings("Java7ApiChecker")
@IgnoreJRERequirement // Users will use this only if they're already using streams.
public static <T extends @Nullable Object, E>
Collector<T, ?, ImmutableMultiset<E>> toImmutableMultiset(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public class ImmutableRangeMap<K extends Comparable<?>, V> implements RangeMap<K
*
* @since 33.2.0 (available since 23.1 in guava-jre)
*/
@SuppressWarnings({"AndroidJdkLibsChecker", "Java7ApiChecker"})
@SuppressWarnings("Java7ApiChecker")
@IgnoreJRERequirement // Users will use this only if they're already using streams.
public static <T extends @Nullable Object, K extends Comparable<? super K>, V>
Collector<T, ?, ImmutableRangeMap<K, V>> toImmutableRangeMap(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public final class ImmutableRangeSet<C extends Comparable> extends AbstractRange
*
* @since 33.2.0 (available since 23.1 in guava-jre)
*/
@SuppressWarnings({"AndroidJdkLibsChecker", "Java7ApiChecker"})
@SuppressWarnings("Java7ApiChecker")
@IgnoreJRERequirement // Users will use this only if they're already using streams.
public static <E extends Comparable<? super E>>
Collector<Range<E>, ?, ImmutableRangeSet<E>> toImmutableRangeSet() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public abstract class ImmutableSet<E> extends ImmutableCollection<E> implements
*
* @since 33.2.0 (available since 21.0 in guava-jre)
*/
@SuppressWarnings({"AndroidJdkLibsChecker", "Java7ApiChecker"})
@SuppressWarnings("Java7ApiChecker")
@IgnoreJRERequirement // Users will use this only if they're already using streams.
public static <E> Collector<E, ?, ImmutableSet<E>> toImmutableSet() {
return CollectCollectors.toImmutableSet();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public class ImmutableSetMultimap<K, V> extends ImmutableMultimap<K, V>
*
* @since 33.2.0 (available since 21.0 in guava-jre)
*/
@SuppressWarnings({"AndroidJdkLibsChecker", "Java7ApiChecker"})
@SuppressWarnings("Java7ApiChecker")
@IgnoreJRERequirement // Users will use this only if they're already using streams.
public static <T extends @Nullable Object, K, V>
Collector<T, ?, ImmutableSetMultimap<K, V>> toImmutableSetMultimap(
Expand Down Expand Up @@ -140,7 +140,7 @@ public class ImmutableSetMultimap<K, V> extends ImmutableMultimap<K, V>
*
* @since 33.2.0 (available since 21.0 in guava-jre)
*/
@SuppressWarnings({"AndroidJdkLibsChecker", "Java7ApiChecker"})
@SuppressWarnings("Java7ApiChecker")
@IgnoreJRERequirement // Users will use this only if they're already using streams.
public static <T extends @Nullable Object, K, V>
Collector<T, ?, ImmutableSetMultimap<K, V>> flatteningToImmutableSetMultimap(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public final class ImmutableSortedMap<K, V> extends ImmutableMap<K, V>
*
* @since 33.2.0 (available since 21.0 in guava-jre)
*/
@SuppressWarnings({"AndroidJdkLibsChecker", "Java7ApiChecker"})
@SuppressWarnings("Java7ApiChecker")
@IgnoreJRERequirement // Users will use this only if they're already using streams.
public static <T extends @Nullable Object, K, V>
Collector<T, ?, ImmutableSortedMap<K, V>> toImmutableSortedMap(
Expand All @@ -97,7 +97,7 @@ public final class ImmutableSortedMap<K, V> extends ImmutableMap<K, V>
*
* @since 33.2.0 (available since 21.0 in guava-jre)
*/
@SuppressWarnings({"AndroidJdkLibsChecker", "Java7ApiChecker"})
@SuppressWarnings("Java7ApiChecker")
@IgnoreJRERequirement // Users will use this only if they're already using streams.
public static <T extends @Nullable Object, K, V>
Collector<T, ?, ImmutableSortedMap<K, V>> toImmutableSortedMap(
Expand Down Expand Up @@ -1223,7 +1223,7 @@ private void readObject(ObjectInputStream stream) throws InvalidObjectException
*/
@DoNotCall("Use toImmutableSortedMap")
@Deprecated
@SuppressWarnings({"AndroidJdkLibsChecker", "Java7ApiChecker"})
@SuppressWarnings("Java7ApiChecker")
@IgnoreJRERequirement // Users will use this only if they're already using streams.
public static <T extends @Nullable Object, K, V>
Collector<T, ?, ImmutableMap<K, V>> toImmutableMap(
Expand All @@ -1243,7 +1243,7 @@ private void readObject(ObjectInputStream stream) throws InvalidObjectException
*/
@DoNotCall("Use toImmutableSortedMap")
@Deprecated
@SuppressWarnings({"AndroidJdkLibsChecker", "Java7ApiChecker"})
@SuppressWarnings("Java7ApiChecker")
@IgnoreJRERequirement // Users will use this only if they're already using streams.
public static <T extends @Nullable Object, K, V>
Collector<T, ?, ImmutableMap<K, V>> toImmutableMap(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public abstract class ImmutableSortedMultiset<E> extends ImmutableMultiset<E>
*
* @since 33.2.0 (available since 21.0 in guava-jre)
*/
@SuppressWarnings({"AndroidJdkLibsChecker", "Java7ApiChecker"})
@SuppressWarnings("Java7ApiChecker")
@IgnoreJRERequirement // Users will use this only if they're already using streams.
public static <E> Collector<E, ?, ImmutableSortedMultiset<E>> toImmutableSortedMultiset(
Comparator<? super E> comparator) {
Expand All @@ -88,7 +88,7 @@ public abstract class ImmutableSortedMultiset<E> extends ImmutableMultiset<E>
*
* @since 33.2.0 (available since 22.0 in guava-jre)
*/
@SuppressWarnings({"AndroidJdkLibsChecker", "Java7ApiChecker"})
@SuppressWarnings("Java7ApiChecker")
@IgnoreJRERequirement // Users will use this only if they're already using streams.
public static <T extends @Nullable Object, E>
Collector<T, ?, ImmutableSortedMultiset<E>> toImmutableSortedMultiset(
Expand All @@ -108,7 +108,7 @@ public abstract class ImmutableSortedMultiset<E> extends ImmutableMultiset<E>
(Multiset<E> multiset) -> copyOfSortedEntries(comparator, multiset.entrySet()));
}

@SuppressWarnings({"AndroidJdkLibsChecker", "Java7ApiChecker"})
@SuppressWarnings("Java7ApiChecker")
@IgnoreJRERequirement // helper for toImmutableSortedMultiset
/*
* If we make these calls inline inside toImmutableSortedMultiset, we get an Animal Sniffer error,
Expand Down Expand Up @@ -761,7 +761,7 @@ private void readObject(ObjectInputStream stream) throws InvalidObjectException
*/
@DoNotCall("Use toImmutableSortedMultiset.")
@Deprecated
@SuppressWarnings({"AndroidJdkLibsChecker", "Java7ApiChecker"})
@SuppressWarnings("Java7ApiChecker")
@IgnoreJRERequirement // Users will use this only if they're already using streams.
public static <E> Collector<E, ?, ImmutableMultiset<E>> toImmutableMultiset() {
throw new UnsupportedOperationException();
Expand All @@ -778,7 +778,7 @@ private void readObject(ObjectInputStream stream) throws InvalidObjectException
*/
@DoNotCall("Use toImmutableSortedMultiset.")
@Deprecated
@SuppressWarnings({"AndroidJdkLibsChecker", "Java7ApiChecker"})
@SuppressWarnings("Java7ApiChecker")
@IgnoreJRERequirement // Users will use this only if they're already using streams.
public static <T extends @Nullable Object, E>
Collector<T, ?, ImmutableMultiset<E>> toImmutableMultiset(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public abstract class ImmutableSortedSet<E> extends ImmutableSet<E>
*
* @since 33.2.0 (available since 21.0 in guava-jre)
*/
@SuppressWarnings({"AndroidJdkLibsChecker", "Java7ApiChecker"})
@SuppressWarnings("Java7ApiChecker")
@IgnoreJRERequirement // Users will use this only if they're already using streams.
public static <E> Collector<E, ?, ImmutableSortedSet<E>> toImmutableSortedSet(
Comparator<? super E> comparator) {
Expand Down Expand Up @@ -803,7 +803,7 @@ Object writeReplace() {
*/
@DoNotCall("Use toImmutableSortedSet")
@Deprecated
@SuppressWarnings({"AndroidJdkLibsChecker", "Java7ApiChecker"})
@SuppressWarnings("Java7ApiChecker")
@IgnoreJRERequirement // Users will use this only if they're already using streams.
public static <E> Collector<E, ?, ImmutableSet<E>> toImmutableSet() {
throw new UnsupportedOperationException();
Expand Down
Loading

0 comments on commit 702e4b2

Please sign in to comment.