Skip to content

Commit 8a1c90e

Browse files
cpovirkGoogle Java Core Libraries
authored andcommitted
Prepare for usage of ReflectionFreeAssertThrows from more packages:
- Make `AbstractPackageSanityTests` ignore the class for simplicity. (But also add null checks (which solve only _part_ of the problem) to `ReflectionFreeAssertThrows` because why not.) - Remove support for `util.concurrent` types so that we can also remove `util.concurrent` deps (mostly added during cl/675634517 and cl/686155720). I'll include support for those types in the packages that actually need it. RELNOTES=n/a PiperOrigin-RevId: 687009402
1 parent 9597b0d commit 8a1c90e

File tree

8 files changed

+44
-18
lines changed

8 files changed

+44
-18
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,15 @@ public void testSerializable() throws Exception {
232232
@Test
233233
public void testNulls() throws Exception {
234234
for (Class<?> classToTest : findClassesToTest(loadClassesInPackage(), NULL_TEST_METHOD_NAMES)) {
235+
if (classToTest.getSimpleName().equals("ReflectionFreeAssertThrows")) {
236+
/*
237+
* These classes handle null properly but throw IllegalArgumentException for the default
238+
* Class argument that this test uses. Normally we'd fix that by declaring a
239+
* ReflectionFreeAssertThrowsTest with a testNulls method, but that's annoying to have to do
240+
* for a package-private utility class. So we skip the class entirely instead.
241+
*/
242+
continue;
243+
}
235244
try {
236245
tester.doTestNulls(classToTest, visibility);
237246
} catch (Throwable e) {

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
package com.google.common.base;
1616

17+
import static com.google.common.base.Preconditions.checkNotNull;
18+
1719
import com.google.common.annotations.GwtCompatible;
1820
import com.google.common.annotations.GwtIncompatible;
1921
import com.google.common.annotations.J2ktIncompatible;
@@ -22,8 +24,6 @@
2224
import com.google.common.base.TestExceptions.SomeOtherCheckedException;
2325
import com.google.common.base.TestExceptions.SomeUncheckedException;
2426
import com.google.common.collect.ImmutableMap;
25-
import com.google.common.util.concurrent.ExecutionError;
26-
import com.google.common.util.concurrent.UncheckedExecutionException;
2727
import com.google.errorprone.annotations.CanIgnoreReturnValue;
2828
import java.lang.reflect.InvocationTargetException;
2929
import java.nio.charset.UnsupportedCharsetException;
@@ -67,6 +67,8 @@ static <T extends Throwable> T assertThrows(
6767

6868
private static <T extends Throwable> T doAssertThrows(
6969
Class<T> expectedThrowable, ThrowingSupplier supplier, boolean userPassedSupplier) {
70+
checkNotNull(expectedThrowable);
71+
checkNotNull(supplier);
7072
Predicate<Throwable> predicate = INSTANCE_OF.get(expectedThrowable);
7173
if (predicate == null) {
7274
throw new IllegalArgumentException(
@@ -132,7 +134,6 @@ ImmutableMap<Class<? extends Throwable>, Predicate<Throwable>> exceptions() {
132134
.put(
133135
ConcurrentModificationException.class,
134136
e -> e instanceof ConcurrentModificationException)
135-
.put(ExecutionError.class, e -> e instanceof ExecutionError)
136137
.put(ExecutionException.class, e -> e instanceof ExecutionException)
137138
.put(IllegalArgumentException.class, e -> e instanceof IllegalArgumentException)
138139
.put(IllegalStateException.class, e -> e instanceof IllegalStateException)
@@ -146,7 +147,6 @@ ImmutableMap<Class<? extends Throwable>, Predicate<Throwable>> exceptions() {
146147
.put(SomeOtherCheckedException.class, e -> e instanceof SomeOtherCheckedException)
147148
.put(SomeUncheckedException.class, e -> e instanceof SomeUncheckedException)
148149
.put(TimeoutException.class, e -> e instanceof TimeoutException)
149-
.put(UncheckedExecutionException.class, e -> e instanceof UncheckedExecutionException)
150150
.put(UnsupportedCharsetException.class, e -> e instanceof UnsupportedCharsetException)
151151
.put(UnsupportedOperationException.class, e -> e instanceof UnsupportedOperationException)
152152
.put(VerifyException.class, e -> e instanceof VerifyException)

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
package com.google.common.collect;
1616

17+
import static com.google.common.base.Preconditions.checkNotNull;
18+
1719
import com.google.common.annotations.GwtCompatible;
1820
import com.google.common.annotations.GwtIncompatible;
1921
import com.google.common.annotations.J2ktIncompatible;
@@ -24,8 +26,6 @@
2426
import com.google.common.collect.TestExceptions.SomeError;
2527
import com.google.common.collect.TestExceptions.SomeOtherCheckedException;
2628
import com.google.common.collect.TestExceptions.SomeUncheckedException;
27-
import com.google.common.util.concurrent.ExecutionError;
28-
import com.google.common.util.concurrent.UncheckedExecutionException;
2929
import com.google.errorprone.annotations.CanIgnoreReturnValue;
3030
import java.lang.reflect.InvocationTargetException;
3131
import java.nio.charset.UnsupportedCharsetException;
@@ -69,6 +69,8 @@ static <T extends Throwable> T assertThrows(
6969

7070
private static <T extends Throwable> T doAssertThrows(
7171
Class<T> expectedThrowable, ThrowingSupplier supplier, boolean userPassedSupplier) {
72+
checkNotNull(expectedThrowable);
73+
checkNotNull(supplier);
7274
Predicate<Throwable> predicate = INSTANCE_OF.get(expectedThrowable);
7375
if (predicate == null) {
7476
throw new IllegalArgumentException(
@@ -134,7 +136,6 @@ ImmutableMap<Class<? extends Throwable>, Predicate<Throwable>> exceptions() {
134136
.put(
135137
ConcurrentModificationException.class,
136138
e -> e instanceof ConcurrentModificationException)
137-
.put(ExecutionError.class, e -> e instanceof ExecutionError)
138139
.put(ExecutionException.class, e -> e instanceof ExecutionException)
139140
.put(IllegalArgumentException.class, e -> e instanceof IllegalArgumentException)
140141
.put(IllegalStateException.class, e -> e instanceof IllegalStateException)
@@ -149,7 +150,6 @@ ImmutableMap<Class<? extends Throwable>, Predicate<Throwable>> exceptions() {
149150
.put(SomeOtherCheckedException.class, e -> e instanceof SomeOtherCheckedException)
150151
.put(SomeUncheckedException.class, e -> e instanceof SomeUncheckedException)
151152
.put(TimeoutException.class, e -> e instanceof TimeoutException)
152-
.put(UncheckedExecutionException.class, e -> e instanceof UncheckedExecutionException)
153153
.put(UnsupportedCharsetException.class, e -> e instanceof UnsupportedCharsetException)
154154
.put(UnsupportedOperationException.class, e -> e instanceof UnsupportedOperationException)
155155
.put(VerifyException.class, e -> e instanceof VerifyException)

android/guava/src/com/google/common/collect/ImmutableSortedMap.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,11 @@ public static <K extends Comparable<? super K>, V> ImmutableSortedMap<K, V> of(
295295
V v8,
296296
K k9,
297297
V v9) {
298-
return fromEntries(
298+
/*
299+
* This explicit type parameter works around what seems to be a javac bug in certain
300+
* configurations: b/339186525#comment6
301+
*/
302+
return ImmutableSortedMap.<K, V>fromEntries(
299303
entryOf(k1, v1),
300304
entryOf(k2, v2),
301305
entryOf(k3, v3),

guava-testlib/src/com/google/common/testing/AbstractPackageSanityTests.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,15 @@ public void testSerializable() throws Exception {
233233
@Test
234234
public void testNulls() throws Exception {
235235
for (Class<?> classToTest : findClassesToTest(loadClassesInPackage(), NULL_TEST_METHOD_NAMES)) {
236+
if (classToTest.getSimpleName().equals("ReflectionFreeAssertThrows")) {
237+
/*
238+
* These classes handle null properly but throw IllegalArgumentException for the default
239+
* Class argument that this test uses. Normally we'd fix that by declaring a
240+
* ReflectionFreeAssertThrowsTest with a testNulls method, but that's annoying to have to do
241+
* for a package-private utility class. So we skip the class entirely instead.
242+
*/
243+
continue;
244+
}
236245
try {
237246
tester.doTestNulls(classToTest, visibility);
238247
} catch (Throwable e) {

guava-tests/test/com/google/common/base/ReflectionFreeAssertThrows.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
package com.google.common.base;
1616

17+
import static com.google.common.base.Preconditions.checkNotNull;
18+
1719
import com.google.common.annotations.GwtCompatible;
1820
import com.google.common.annotations.GwtIncompatible;
1921
import com.google.common.annotations.J2ktIncompatible;
@@ -22,8 +24,6 @@
2224
import com.google.common.base.TestExceptions.SomeOtherCheckedException;
2325
import com.google.common.base.TestExceptions.SomeUncheckedException;
2426
import com.google.common.collect.ImmutableMap;
25-
import com.google.common.util.concurrent.ExecutionError;
26-
import com.google.common.util.concurrent.UncheckedExecutionException;
2727
import com.google.errorprone.annotations.CanIgnoreReturnValue;
2828
import java.lang.reflect.InvocationTargetException;
2929
import java.nio.charset.UnsupportedCharsetException;
@@ -67,6 +67,8 @@ static <T extends Throwable> T assertThrows(
6767

6868
private static <T extends Throwable> T doAssertThrows(
6969
Class<T> expectedThrowable, ThrowingSupplier supplier, boolean userPassedSupplier) {
70+
checkNotNull(expectedThrowable);
71+
checkNotNull(supplier);
7072
Predicate<Throwable> predicate = INSTANCE_OF.get(expectedThrowable);
7173
if (predicate == null) {
7274
throw new IllegalArgumentException(
@@ -132,7 +134,6 @@ ImmutableMap<Class<? extends Throwable>, Predicate<Throwable>> exceptions() {
132134
.put(
133135
ConcurrentModificationException.class,
134136
e -> e instanceof ConcurrentModificationException)
135-
.put(ExecutionError.class, e -> e instanceof ExecutionError)
136137
.put(ExecutionException.class, e -> e instanceof ExecutionException)
137138
.put(IllegalArgumentException.class, e -> e instanceof IllegalArgumentException)
138139
.put(IllegalStateException.class, e -> e instanceof IllegalStateException)
@@ -146,7 +147,6 @@ ImmutableMap<Class<? extends Throwable>, Predicate<Throwable>> exceptions() {
146147
.put(SomeOtherCheckedException.class, e -> e instanceof SomeOtherCheckedException)
147148
.put(SomeUncheckedException.class, e -> e instanceof SomeUncheckedException)
148149
.put(TimeoutException.class, e -> e instanceof TimeoutException)
149-
.put(UncheckedExecutionException.class, e -> e instanceof UncheckedExecutionException)
150150
.put(UnsupportedCharsetException.class, e -> e instanceof UnsupportedCharsetException)
151151
.put(UnsupportedOperationException.class, e -> e instanceof UnsupportedOperationException)
152152
.put(VerifyException.class, e -> e instanceof VerifyException)

guava-tests/test/com/google/common/collect/ReflectionFreeAssertThrows.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
package com.google.common.collect;
1616

17+
import static com.google.common.base.Preconditions.checkNotNull;
18+
1719
import com.google.common.annotations.GwtCompatible;
1820
import com.google.common.annotations.GwtIncompatible;
1921
import com.google.common.annotations.J2ktIncompatible;
@@ -24,8 +26,6 @@
2426
import com.google.common.collect.TestExceptions.SomeError;
2527
import com.google.common.collect.TestExceptions.SomeOtherCheckedException;
2628
import com.google.common.collect.TestExceptions.SomeUncheckedException;
27-
import com.google.common.util.concurrent.ExecutionError;
28-
import com.google.common.util.concurrent.UncheckedExecutionException;
2929
import com.google.errorprone.annotations.CanIgnoreReturnValue;
3030
import java.lang.reflect.InvocationTargetException;
3131
import java.nio.charset.UnsupportedCharsetException;
@@ -69,6 +69,8 @@ static <T extends Throwable> T assertThrows(
6969

7070
private static <T extends Throwable> T doAssertThrows(
7171
Class<T> expectedThrowable, ThrowingSupplier supplier, boolean userPassedSupplier) {
72+
checkNotNull(expectedThrowable);
73+
checkNotNull(supplier);
7274
Predicate<Throwable> predicate = INSTANCE_OF.get(expectedThrowable);
7375
if (predicate == null) {
7476
throw new IllegalArgumentException(
@@ -134,7 +136,6 @@ ImmutableMap<Class<? extends Throwable>, Predicate<Throwable>> exceptions() {
134136
.put(
135137
ConcurrentModificationException.class,
136138
e -> e instanceof ConcurrentModificationException)
137-
.put(ExecutionError.class, e -> e instanceof ExecutionError)
138139
.put(ExecutionException.class, e -> e instanceof ExecutionException)
139140
.put(IllegalArgumentException.class, e -> e instanceof IllegalArgumentException)
140141
.put(IllegalStateException.class, e -> e instanceof IllegalStateException)
@@ -149,7 +150,6 @@ ImmutableMap<Class<? extends Throwable>, Predicate<Throwable>> exceptions() {
149150
.put(SomeOtherCheckedException.class, e -> e instanceof SomeOtherCheckedException)
150151
.put(SomeUncheckedException.class, e -> e instanceof SomeUncheckedException)
151152
.put(TimeoutException.class, e -> e instanceof TimeoutException)
152-
.put(UncheckedExecutionException.class, e -> e instanceof UncheckedExecutionException)
153153
.put(UnsupportedCharsetException.class, e -> e instanceof UnsupportedCharsetException)
154154
.put(UnsupportedOperationException.class, e -> e instanceof UnsupportedOperationException)
155155
.put(VerifyException.class, e -> e instanceof VerifyException)

guava/src/com/google/common/collect/ImmutableSortedMap.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,11 @@ public static <K extends Comparable<? super K>, V> ImmutableSortedMap<K, V> of(
294294
V v8,
295295
K k9,
296296
V v9) {
297-
return fromEntries(
297+
/*
298+
* This explicit type parameter works around what seems to be a javac bug in certain
299+
* configurations: b/339186525#comment6
300+
*/
301+
return ImmutableSortedMap.<K, V>fromEntries(
298302
entryOf(k1, v1),
299303
entryOf(k2, v2),
300304
entryOf(k3, v3),

0 commit comments

Comments
 (0)