From 808e0799f3026c0e08500ab5c06deb0952844377 Mon Sep 17 00:00:00 2001 From: cpovirk Date: Fri, 14 Jun 2024 10:50:03 -0700 Subject: [PATCH] Use imports instead of fully qualified types. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I suspect that many of these fully qualified types come from fears that our tools for stripping (e.g.) `@GwtIncompatible` elements will fail to strip imports when they should. (I think that there may specifically have been a problem in Make Open Easy (whose acronym is M-O-E, which would trigger a presubmit error if I removed those hyphens :)) when a comment or Javadoc referred to the simple name of a class that was imported but not actually used.) Some others come from trying to remain in sync with an upstream whose subsequent changes we've probably never actually pulled in (e.g., `JSR166TestCase`). Still others may come from trying to write code that can be copied and pasted from one file to another without touching imports. And some of it probably comes from attempts to suppress `sunapi` warnings (which can't be done on imports)—but those went from "hard to suppress" to "impossible to suppress" a while back, as discussed in cl/637073596. We _might_ actually be better off with the imports, since _maaaaaaybe_ that will lead to only one warning instead of _n_? But I doubt we'd be so lucky. PiperOrigin-RevId: 643394004 --- .../testing/features/TesterAnnotation.java | 3 ++- .../SameThreadScheduledExecutorService.java | 3 ++- .../concurrent/ExecutionListBenchmark.java | 23 ++++++++++------- .../com/google/common/base/SuppliersTest.java | 3 ++- ...bstractFutureFallbackAtomicHelperTest.java | 6 ++--- .../util/concurrent/JSR166TestCase.java | 5 ++-- .../com/google/common/cache/Striped64.java | 25 +++++++++++-------- .../collect/ForwardingNavigableMap.java | 2 +- .../common/collect/TableCollectors.java | 16 ++++++------ .../com/google/common/hash/BloomFilter.java | 2 +- .../src/com/google/common/hash/Striped64.java | 25 +++++++++++-------- .../common/primitives/UnsignedBytes.java | 20 +++++++++------ .../reflect/MutableTypeToInstanceMap.java | 2 +- .../util/concurrent/AbstractFuture.java | 16 ++++++------ .../common/util/concurrent/AtomicDouble.java | 11 +++++--- .../util/concurrent/AtomicDoubleArray.java | 11 +++++--- .../testing/features/TesterAnnotation.java | 3 ++- .../SameThreadScheduledExecutorService.java | 3 ++- .../common/testing/NullPointerTesterTest.java | 17 ++++++------- .../concurrent/ExecutionListBenchmark.java | 23 ++++++++++------- .../com/google/common/base/SuppliersTest.java | 3 ++- .../google/common/reflect/ClassPathTest.java | 13 +++++----- ...bstractFutureFallbackAtomicHelperTest.java | 6 ++--- .../util/concurrent/JSR166TestCase.java | 5 ++-- .../com/google/common/cache/Striped64.java | 25 +++++++++++-------- .../collect/ForwardingNavigableMap.java | 2 +- .../src/com/google/common/collect/Queues.java | 8 +++--- .../common/collect/TableCollectors.java | 16 ++++++------ .../com/google/common/hash/BloomFilter.java | 2 +- .../src/com/google/common/hash/Striped64.java | 25 +++++++++++-------- .../common/primitives/UnsignedBytes.java | 20 +++++++++------ .../reflect/MutableTypeToInstanceMap.java | 2 +- .../util/concurrent/AbstractFuture.java | 16 ++++++------ .../common/util/concurrent/AtomicDouble.java | 11 +++++--- .../util/concurrent/AtomicDoubleArray.java | 11 +++++--- 35 files changed, 221 insertions(+), 163 deletions(-) diff --git a/android/guava-testlib/src/com/google/common/collect/testing/features/TesterAnnotation.java b/android/guava-testlib/src/com/google/common/collect/testing/features/TesterAnnotation.java index 1831e417f08e..247c62a7067a 100644 --- a/android/guava-testlib/src/com/google/common/collect/testing/features/TesterAnnotation.java +++ b/android/guava-testlib/src/com/google/common/collect/testing/features/TesterAnnotation.java @@ -16,6 +16,7 @@ import com.google.common.annotations.GwtCompatible; import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; @@ -29,7 +30,7 @@ * * @author George van den Driessche */ -@Target(value = {java.lang.annotation.ElementType.ANNOTATION_TYPE}) +@Target(value = {ElementType.ANNOTATION_TYPE}) @Retention(value = RetentionPolicy.RUNTIME) @Documented @GwtCompatible diff --git a/android/guava-testlib/src/com/google/common/util/concurrent/testing/SameThreadScheduledExecutorService.java b/android/guava-testlib/src/com/google/common/util/concurrent/testing/SameThreadScheduledExecutorService.java index 25b7ef791c00..65b8b4f13e90 100644 --- a/android/guava-testlib/src/com/google/common/util/concurrent/testing/SameThreadScheduledExecutorService.java +++ b/android/guava-testlib/src/com/google/common/util/concurrent/testing/SameThreadScheduledExecutorService.java @@ -31,6 +31,7 @@ import java.util.concurrent.Callable; import java.util.concurrent.Delayed; import java.util.concurrent.ExecutionException; +import java.util.concurrent.Executors; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; @@ -135,7 +136,7 @@ public void execute(Runnable command) { public ListenableScheduledFuture schedule(Runnable command, long delay, TimeUnit unit) { Preconditions.checkNotNull(command, "command must not be null"); Preconditions.checkNotNull(unit, "unit must not be null!"); - return schedule(java.util.concurrent.Executors.callable(command), delay, unit); + return schedule(Executors.callable(command), delay, unit); } @Override diff --git a/android/guava-tests/benchmark/com/google/common/util/concurrent/ExecutionListBenchmark.java b/android/guava-tests/benchmark/com/google/common/util/concurrent/ExecutionListBenchmark.java index d1c2dfade8ec..b866336b84a8 100644 --- a/android/guava-tests/benchmark/com/google/common/util/concurrent/ExecutionListBenchmark.java +++ b/android/guava-tests/benchmark/com/google/common/util/concurrent/ExecutionListBenchmark.java @@ -28,6 +28,10 @@ import com.google.common.collect.Lists; import com.google.common.util.concurrent.AbstractFutureBenchmarks.OldAbstractFuture; import com.google.errorprone.annotations.concurrent.GuardedBy; +import java.lang.reflect.Field; +import java.security.AccessController; +import java.security.PrivilegedActionException; +import java.security.PrivilegedExceptionAction; import java.util.Queue; import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.CountDownLatch; @@ -39,6 +43,7 @@ import java.util.logging.Level; import java.util.logging.Logger; import org.checkerframework.checker.nullness.qual.Nullable; +import sun.misc.Unsafe; /** Benchmarks for {@link ExecutionList}. */ @VmOptions({"-Xms8g", "-Xmx8g"}) @@ -577,7 +582,7 @@ private static final class RunnableExecutorPair { private static final class ExecutionListCAS { static final Logger log = Logger.getLogger(ExecutionListCAS.class.getName()); - private static final sun.misc.Unsafe UNSAFE; + private static final Unsafe UNSAFE; private static final long HEAD_OFFSET; /** @@ -596,18 +601,18 @@ private static final class ExecutionListCAS { } /** TODO(lukes): This was copied verbatim from Striped64.java... standardize this? */ - private static sun.misc.Unsafe getUnsafe() { + private static Unsafe getUnsafe() { try { - return sun.misc.Unsafe.getUnsafe(); + return Unsafe.getUnsafe(); } catch (SecurityException tryReflectionInstead) { } try { - return java.security.AccessController.doPrivileged( - new java.security.PrivilegedExceptionAction() { + return AccessController.doPrivileged( + new PrivilegedExceptionAction() { @Override - public sun.misc.Unsafe run() throws Exception { - Class k = sun.misc.Unsafe.class; - for (java.lang.reflect.Field f : k.getDeclaredFields()) { + public Unsafe run() throws Exception { + Class k = Unsafe.class; + for (Field f : k.getDeclaredFields()) { f.setAccessible(true); Object x = f.get(null); if (k.isInstance(x)) return k.cast(x); @@ -615,7 +620,7 @@ public sun.misc.Unsafe run() throws Exception { throw new NoSuchFieldError("the Unsafe"); } }); - } catch (java.security.PrivilegedActionException e) { + } catch (PrivilegedActionException e) { throw new RuntimeException("Could not initialize intrinsics", e.getCause()); } } diff --git a/android/guava-tests/test/com/google/common/base/SuppliersTest.java b/android/guava-tests/test/com/google/common/base/SuppliersTest.java index 04c837d78205..1954c164c076 100644 --- a/android/guava-tests/test/com/google/common/base/SuppliersTest.java +++ b/android/guava-tests/test/com/google/common/base/SuppliersTest.java @@ -26,6 +26,7 @@ import com.google.common.collect.Lists; import com.google.common.testing.ClassSanityTester; import com.google.common.testing.EqualsTester; +import java.io.NotSerializableException; import java.io.Serializable; import java.time.Duration; import java.util.ArrayList; @@ -145,7 +146,7 @@ public void testMemoizeNonSerializable() throws Exception { // Should get an exception when we try to serialize. RuntimeException ex = assertThrows(RuntimeException.class, () -> reserialize(memoizedSupplier)); - assertThat(ex).hasCauseThat().isInstanceOf(java.io.NotSerializableException.class); + assertThat(ex).hasCauseThat().isInstanceOf(NotSerializableException.class); } @J2ktIncompatible diff --git a/android/guava-tests/test/com/google/common/util/concurrent/AbstractFutureFallbackAtomicHelperTest.java b/android/guava-tests/test/com/google/common/util/concurrent/AbstractFutureFallbackAtomicHelperTest.java index 0bcb6adf56c4..42cb8a1fbecc 100644 --- a/android/guava-tests/test/com/google/common/util/concurrent/AbstractFutureFallbackAtomicHelperTest.java +++ b/android/guava-tests/test/com/google/common/util/concurrent/AbstractFutureFallbackAtomicHelperTest.java @@ -23,6 +23,7 @@ import java.util.concurrent.atomic.AtomicReferenceFieldUpdater; import junit.framework.TestCase; import junit.framework.TestSuite; +import sun.misc.Unsafe; /** * Tests our AtomicHelper fallback strategies in AbstractFuture. @@ -55,7 +56,7 @@ public class AbstractFutureFallbackAtomicHelperTest extends TestCase { */ @SuppressWarnings({"SunApi", "removal"}) // b/345822163 private static final ClassLoader NO_UNSAFE = - getClassLoader(ImmutableSet.of(sun.misc.Unsafe.class.getName())); + getClassLoader(ImmutableSet.of(Unsafe.class.getName())); /** * This classloader disallows {@link sun.misc.Unsafe} and {@link AtomicReferenceFieldUpdater}, @@ -64,8 +65,7 @@ public class AbstractFutureFallbackAtomicHelperTest extends TestCase { @SuppressWarnings({"SunApi", "removal"}) // b/345822163 private static final ClassLoader NO_ATOMIC_REFERENCE_FIELD_UPDATER = getClassLoader( - ImmutableSet.of( - sun.misc.Unsafe.class.getName(), AtomicReferenceFieldUpdater.class.getName())); + ImmutableSet.of(Unsafe.class.getName(), AtomicReferenceFieldUpdater.class.getName())); public static TestSuite suite() { // we create a test suite containing a test for every AbstractFutureTest test method and we diff --git a/android/guava-tests/test/com/google/common/util/concurrent/JSR166TestCase.java b/android/guava-tests/test/com/google/common/util/concurrent/JSR166TestCase.java index 3d72790a7dc5..645af76f3f4e 100644 --- a/android/guava-tests/test/com/google/common/util/concurrent/JSR166TestCase.java +++ b/android/guava-tests/test/com/google/common/util/concurrent/JSR166TestCase.java @@ -20,6 +20,7 @@ import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; +import java.io.FilePermission; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.security.CodeSource; @@ -590,7 +591,7 @@ public void runWithoutPermissions(Runnable r) { } /** A security policy where new permissions can be dynamically added or all cleared. */ - public static class AdjustablePolicy extends java.security.Policy { + public static class AdjustablePolicy extends Policy { Permissions perms = new Permissions(); AdjustablePolicy(Permission... permissions) { @@ -639,7 +640,7 @@ public static Policy permissivePolicy() { // Permissions needed by the junit test harness new RuntimePermission("accessDeclaredMembers"), new PropertyPermission("*", "read"), - new java.io.FilePermission("<>", "read")); + new FilePermission("<>", "read")); } /** Sleeps until the given time has elapsed. Throws AssertionFailedError if interrupted. */ diff --git a/android/guava/src/com/google/common/cache/Striped64.java b/android/guava/src/com/google/common/cache/Striped64.java index ab05853281e3..e8be86e36e5d 100644 --- a/android/guava/src/com/google/common/cache/Striped64.java +++ b/android/guava/src/com/google/common/cache/Striped64.java @@ -12,9 +12,14 @@ package com.google.common.cache; import com.google.common.annotations.GwtIncompatible; +import java.lang.reflect.Field; +import java.security.AccessController; +import java.security.PrivilegedActionException; +import java.security.PrivilegedExceptionAction; import java.util.Random; import javax.annotation.CheckForNull; import org.checkerframework.checker.nullness.qual.Nullable; +import sun.misc.Unsafe; /** * A package-local class holding common representation and mechanics for classes supporting dynamic @@ -109,7 +114,7 @@ final boolean cas(long cmp, long val) { } // Unsafe mechanics - private static final sun.misc.Unsafe UNSAFE; + private static final Unsafe UNSAFE; private static final long valueOffset; static { @@ -267,7 +272,7 @@ final void internalReset(long initialValue) { } // Unsafe mechanics - private static final sun.misc.Unsafe UNSAFE; + private static final Unsafe UNSAFE; private static final long baseOffset; private static final long busyOffset; @@ -288,18 +293,18 @@ final void internalReset(long initialValue) { * * @return a sun.misc.Unsafe */ - private static sun.misc.Unsafe getUnsafe() { + private static Unsafe getUnsafe() { try { - return sun.misc.Unsafe.getUnsafe(); + return Unsafe.getUnsafe(); } catch (SecurityException tryReflectionInstead) { } try { - return java.security.AccessController.doPrivileged( - new java.security.PrivilegedExceptionAction() { + return AccessController.doPrivileged( + new PrivilegedExceptionAction() { @Override - public sun.misc.Unsafe run() throws Exception { - Class k = sun.misc.Unsafe.class; - for (java.lang.reflect.Field f : k.getDeclaredFields()) { + public Unsafe run() throws Exception { + Class k = Unsafe.class; + for (Field f : k.getDeclaredFields()) { f.setAccessible(true); Object x = f.get(null); if (k.isInstance(x)) return k.cast(x); @@ -307,7 +312,7 @@ public sun.misc.Unsafe run() throws Exception { throw new NoSuchFieldError("the Unsafe"); } }); - } catch (java.security.PrivilegedActionException e) { + } catch (PrivilegedActionException e) { throw new RuntimeException("Could not initialize intrinsics", e.getCause()); } } diff --git a/android/guava/src/com/google/common/collect/ForwardingNavigableMap.java b/android/guava/src/com/google/common/collect/ForwardingNavigableMap.java index 87ebc9898c30..c7f0d0fe2f78 100644 --- a/android/guava/src/com/google/common/collect/ForwardingNavigableMap.java +++ b/android/guava/src/com/google/common/collect/ForwardingNavigableMap.java @@ -320,7 +320,7 @@ public boolean hasNext() { } @Override - public java.util.Map.Entry next() { + public Entry next() { if (nextOrNull == null) { throw new NoSuchElementException(); } diff --git a/android/guava/src/com/google/common/collect/TableCollectors.java b/android/guava/src/com/google/common/collect/TableCollectors.java index f53569627e5e..76e60500850b 100644 --- a/android/guava/src/com/google/common/collect/TableCollectors.java +++ b/android/guava/src/com/google/common/collect/TableCollectors.java @@ -89,10 +89,10 @@ final class TableCollectors { V, I extends Table> Collector toTable( - java.util.function.Function rowFunction, - java.util.function.Function columnFunction, - java.util.function.Function valueFunction, - java.util.function.Supplier tableSupplier) { + Function rowFunction, + Function columnFunction, + Function valueFunction, + Supplier tableSupplier) { return TableCollectors.toTable( rowFunction, columnFunction, @@ -110,11 +110,11 @@ final class TableCollectors { V, I extends Table> Collector toTable( - java.util.function.Function rowFunction, - java.util.function.Function columnFunction, - java.util.function.Function valueFunction, + Function rowFunction, + Function columnFunction, + Function valueFunction, BinaryOperator mergeFunction, - java.util.function.Supplier tableSupplier) { + Supplier tableSupplier) { checkNotNull(rowFunction); checkNotNull(columnFunction); checkNotNull(valueFunction); diff --git a/android/guava/src/com/google/common/hash/BloomFilter.java b/android/guava/src/com/google/common/hash/BloomFilter.java index 3ae6b68c2297..f041f70054d2 100644 --- a/android/guava/src/com/google/common/hash/BloomFilter.java +++ b/android/guava/src/com/google/common/hash/BloomFilter.java @@ -74,7 +74,7 @@ public final class BloomFilter implements Predicate< * *

Implementations should be collections of pure functions (i.e. stateless). */ - interface Strategy extends java.io.Serializable { + interface Strategy extends Serializable { /** * Sets {@code numHashFunctions} bits of the given bit array, by hashing a user element. diff --git a/android/guava/src/com/google/common/hash/Striped64.java b/android/guava/src/com/google/common/hash/Striped64.java index df6914731dc0..6cbbd7f5aa80 100644 --- a/android/guava/src/com/google/common/hash/Striped64.java +++ b/android/guava/src/com/google/common/hash/Striped64.java @@ -12,9 +12,14 @@ package com.google.common.hash; import com.google.common.annotations.GwtIncompatible; +import java.lang.reflect.Field; +import java.security.AccessController; +import java.security.PrivilegedActionException; +import java.security.PrivilegedExceptionAction; import java.util.Random; import javax.annotation.CheckForNull; import org.checkerframework.checker.nullness.qual.Nullable; +import sun.misc.Unsafe; /** * A package-local class holding common representation and mechanics for classes supporting dynamic @@ -109,7 +114,7 @@ final boolean cas(long cmp, long val) { } // Unsafe mechanics - private static final sun.misc.Unsafe UNSAFE; + private static final Unsafe UNSAFE; private static final long valueOffset; static { @@ -267,7 +272,7 @@ final void internalReset(long initialValue) { } // Unsafe mechanics - private static final sun.misc.Unsafe UNSAFE; + private static final Unsafe UNSAFE; private static final long baseOffset; private static final long busyOffset; @@ -288,18 +293,18 @@ final void internalReset(long initialValue) { * * @return a sun.misc.Unsafe */ - private static sun.misc.Unsafe getUnsafe() { + private static Unsafe getUnsafe() { try { - return sun.misc.Unsafe.getUnsafe(); + return Unsafe.getUnsafe(); } catch (SecurityException tryReflectionInstead) { } try { - return java.security.AccessController.doPrivileged( - new java.security.PrivilegedExceptionAction() { + return AccessController.doPrivileged( + new PrivilegedExceptionAction() { @Override - public sun.misc.Unsafe run() throws Exception { - Class k = sun.misc.Unsafe.class; - for (java.lang.reflect.Field f : k.getDeclaredFields()) { + public Unsafe run() throws Exception { + Class k = Unsafe.class; + for (Field f : k.getDeclaredFields()) { f.setAccessible(true); Object x = f.get(null); if (k.isInstance(x)) return k.cast(x); @@ -307,7 +312,7 @@ public sun.misc.Unsafe run() throws Exception { throw new NoSuchFieldError("the Unsafe"); } }); - } catch (java.security.PrivilegedActionException e) { + } catch (PrivilegedActionException e) { throw new RuntimeException("Could not initialize intrinsics", e.getCause()); } } diff --git a/android/guava/src/com/google/common/primitives/UnsignedBytes.java b/android/guava/src/com/google/common/primitives/UnsignedBytes.java index 739125ff9786..75e0266047a0 100644 --- a/android/guava/src/com/google/common/primitives/UnsignedBytes.java +++ b/android/guava/src/com/google/common/primitives/UnsignedBytes.java @@ -23,7 +23,11 @@ import com.google.common.annotations.J2ktIncompatible; import com.google.common.annotations.VisibleForTesting; import com.google.errorprone.annotations.CanIgnoreReturnValue; +import java.lang.reflect.Field; import java.nio.ByteOrder; +import java.security.AccessController; +import java.security.PrivilegedActionException; +import java.security.PrivilegedExceptionAction; import java.util.Arrays; import java.util.Comparator; import sun.misc.Unsafe; @@ -334,19 +338,19 @@ enum UnsafeComparator implements Comparator { * * @return a sun.misc.Unsafe */ - private static sun.misc.Unsafe getUnsafe() { + private static Unsafe getUnsafe() { try { - return sun.misc.Unsafe.getUnsafe(); + return Unsafe.getUnsafe(); } catch (SecurityException e) { // that's okay; try reflection instead } try { - return java.security.AccessController.doPrivileged( - new java.security.PrivilegedExceptionAction() { + return AccessController.doPrivileged( + new PrivilegedExceptionAction() { @Override - public sun.misc.Unsafe run() throws Exception { - Class k = sun.misc.Unsafe.class; - for (java.lang.reflect.Field f : k.getDeclaredFields()) { + public Unsafe run() throws Exception { + Class k = Unsafe.class; + for (Field f : k.getDeclaredFields()) { f.setAccessible(true); Object x = f.get(null); if (k.isInstance(x)) { @@ -356,7 +360,7 @@ public sun.misc.Unsafe run() throws Exception { throw new NoSuchFieldError("the Unsafe"); } }); - } catch (java.security.PrivilegedActionException e) { + } catch (PrivilegedActionException e) { throw new RuntimeException("Could not initialize intrinsics", e.getCause()); } } diff --git a/android/guava/src/com/google/common/reflect/MutableTypeToInstanceMap.java b/android/guava/src/com/google/common/reflect/MutableTypeToInstanceMap.java index 7690d2eef928..5e95e22633f5 100644 --- a/android/guava/src/com/google/common/reflect/MutableTypeToInstanceMap.java +++ b/android/guava/src/com/google/common/reflect/MutableTypeToInstanceMap.java @@ -162,7 +162,7 @@ public Object[] toArray() { return Iterators.transform(entries, UnmodifiableEntry::new); } - private UnmodifiableEntry(java.util.Map.Entry delegate) { + private UnmodifiableEntry(Entry delegate) { this.delegate = checkNotNull(delegate); } diff --git a/android/guava/src/com/google/common/util/concurrent/AbstractFuture.java b/android/guava/src/com/google/common/util/concurrent/AbstractFuture.java index 95317e089793..305a43535c43 100644 --- a/android/guava/src/com/google/common/util/concurrent/AbstractFuture.java +++ b/android/guava/src/com/google/common/util/concurrent/AbstractFuture.java @@ -28,6 +28,7 @@ import com.google.errorprone.annotations.CanIgnoreReturnValue; import com.google.errorprone.annotations.ForOverride; import com.google.j2objc.annotations.ReflectionSupport; +import java.lang.reflect.Field; import java.security.AccessController; import java.security.PrivilegedActionException; import java.security.PrivilegedExceptionAction; @@ -44,6 +45,7 @@ import java.util.logging.Level; import javax.annotation.CheckForNull; import org.checkerframework.checker.nullness.qual.Nullable; +import sun.misc.Unsafe; /** * An abstract implementation of {@link ListenableFuture}, intended for advanced users only. More @@ -1343,7 +1345,7 @@ abstract boolean casListeners( */ @SuppressWarnings({"SunApi", "removal"}) // b/345822163 private static final class UnsafeAtomicHelper extends AtomicHelper { - static final sun.misc.Unsafe UNSAFE; + static final Unsafe UNSAFE; static final long LISTENERS_OFFSET; static final long WAITERS_OFFSET; static final long VALUE_OFFSET; @@ -1351,18 +1353,18 @@ private static final class UnsafeAtomicHelper extends AtomicHelper { static final long WAITER_NEXT_OFFSET; static { - sun.misc.Unsafe unsafe = null; + Unsafe unsafe = null; try { - unsafe = sun.misc.Unsafe.getUnsafe(); + unsafe = Unsafe.getUnsafe(); } catch (SecurityException tryReflectionInstead) { try { unsafe = AccessController.doPrivileged( - new PrivilegedExceptionAction() { + new PrivilegedExceptionAction() { @Override - public sun.misc.Unsafe run() throws Exception { - Class k = sun.misc.Unsafe.class; - for (java.lang.reflect.Field f : k.getDeclaredFields()) { + public Unsafe run() throws Exception { + Class k = Unsafe.class; + for (Field f : k.getDeclaredFields()) { f.setAccessible(true); Object x = f.get(null); if (k.isInstance(x)) { diff --git a/android/guava/src/com/google/common/util/concurrent/AtomicDouble.java b/android/guava/src/com/google/common/util/concurrent/AtomicDouble.java index 0da3715bea1b..7528307a78b4 100644 --- a/android/guava/src/com/google/common/util/concurrent/AtomicDouble.java +++ b/android/guava/src/com/google/common/util/concurrent/AtomicDouble.java @@ -18,6 +18,10 @@ import static java.lang.Double.longBitsToDouble; import com.google.errorprone.annotations.CanIgnoreReturnValue; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.io.Serializable; import java.util.concurrent.atomic.AtomicLong; /** @@ -50,7 +54,7 @@ * @since 11.0 */ @ElementTypesAreNonnullByDefault -public class AtomicDouble extends Number implements java.io.Serializable { +public class AtomicDouble extends Number implements Serializable { private static final long serialVersionUID = 0L; // We would use AtomicLongFieldUpdater, but it has issues on some Android devices. @@ -227,15 +231,14 @@ public double doubleValue() { * * @serialData The current value is emitted (a {@code double}). */ - private void writeObject(java.io.ObjectOutputStream s) throws java.io.IOException { + private void writeObject(ObjectOutputStream s) throws IOException { s.defaultWriteObject(); s.writeDouble(get()); } /** Reconstitutes the instance from a stream (that is, deserializes it). */ - private void readObject(java.io.ObjectInputStream s) - throws java.io.IOException, ClassNotFoundException { + private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException { s.defaultReadObject(); value = new AtomicLong(); set(s.readDouble()); diff --git a/android/guava/src/com/google/common/util/concurrent/AtomicDoubleArray.java b/android/guava/src/com/google/common/util/concurrent/AtomicDoubleArray.java index b03fba5274cf..c349f3626d51 100644 --- a/android/guava/src/com/google/common/util/concurrent/AtomicDoubleArray.java +++ b/android/guava/src/com/google/common/util/concurrent/AtomicDoubleArray.java @@ -20,6 +20,10 @@ import com.google.common.annotations.J2ktIncompatible; import com.google.common.primitives.ImmutableLongArray; import com.google.errorprone.annotations.CanIgnoreReturnValue; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.io.Serializable; import java.util.concurrent.atomic.AtomicLongArray; /** @@ -47,7 +51,7 @@ @GwtIncompatible @J2ktIncompatible @ElementTypesAreNonnullByDefault -public class AtomicDoubleArray implements java.io.Serializable { +public class AtomicDoubleArray implements Serializable { private static final long serialVersionUID = 0L; // Making this non-final is the lesser evil according to Effective @@ -235,7 +239,7 @@ public String toString() { * @serialData The length of the array is emitted (int), followed by all of its elements (each a * {@code double}) in the proper order. */ - private void writeObject(java.io.ObjectOutputStream s) throws java.io.IOException { + private void writeObject(ObjectOutputStream s) throws IOException { s.defaultWriteObject(); // Write out array length @@ -249,8 +253,7 @@ private void writeObject(java.io.ObjectOutputStream s) throws java.io.IOExceptio } /** Reconstitutes the instance from a stream (that is, deserializes it). */ - private void readObject(java.io.ObjectInputStream s) - throws java.io.IOException, ClassNotFoundException { + private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException { s.defaultReadObject(); int length = s.readInt(); diff --git a/guava-testlib/src/com/google/common/collect/testing/features/TesterAnnotation.java b/guava-testlib/src/com/google/common/collect/testing/features/TesterAnnotation.java index 1831e417f08e..247c62a7067a 100644 --- a/guava-testlib/src/com/google/common/collect/testing/features/TesterAnnotation.java +++ b/guava-testlib/src/com/google/common/collect/testing/features/TesterAnnotation.java @@ -16,6 +16,7 @@ import com.google.common.annotations.GwtCompatible; import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; @@ -29,7 +30,7 @@ * * @author George van den Driessche */ -@Target(value = {java.lang.annotation.ElementType.ANNOTATION_TYPE}) +@Target(value = {ElementType.ANNOTATION_TYPE}) @Retention(value = RetentionPolicy.RUNTIME) @Documented @GwtCompatible diff --git a/guava-testlib/src/com/google/common/util/concurrent/testing/SameThreadScheduledExecutorService.java b/guava-testlib/src/com/google/common/util/concurrent/testing/SameThreadScheduledExecutorService.java index 25b7ef791c00..65b8b4f13e90 100644 --- a/guava-testlib/src/com/google/common/util/concurrent/testing/SameThreadScheduledExecutorService.java +++ b/guava-testlib/src/com/google/common/util/concurrent/testing/SameThreadScheduledExecutorService.java @@ -31,6 +31,7 @@ import java.util.concurrent.Callable; import java.util.concurrent.Delayed; import java.util.concurrent.ExecutionException; +import java.util.concurrent.Executors; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; @@ -135,7 +136,7 @@ public void execute(Runnable command) { public ListenableScheduledFuture schedule(Runnable command, long delay, TimeUnit unit) { Preconditions.checkNotNull(command, "command must not be null"); Preconditions.checkNotNull(unit, "unit must not be null!"); - return schedule(java.util.concurrent.Executors.callable(command), delay, unit); + return schedule(Executors.callable(command), delay, unit); } @Override diff --git a/guava-testlib/test/com/google/common/testing/NullPointerTesterTest.java b/guava-testlib/test/com/google/common/testing/NullPointerTesterTest.java index 573e296485c3..548baf6fbcf9 100644 --- a/guava-testlib/test/com/google/common/testing/NullPointerTesterTest.java +++ b/guava-testlib/test/com/google/common/testing/NullPointerTesterTest.java @@ -46,6 +46,7 @@ import java.util.Map; import java.util.Set; import java.util.SortedSet; +import javax.annotation.CheckForNull; import junit.framework.TestCase; import org.checkerframework.checker.nullness.qual.Nullable; @@ -82,8 +83,7 @@ public static void staticOneArgShouldThrowNpeButDoesnt(String s) { // should catch as failure } - public static void staticOneArgCheckForNullCorrectlyDoesNotThrowNPE( - @javax.annotation.CheckForNull String s) { + public static void staticOneArgCheckForNullCorrectlyDoesNotThrowNPE(@CheckForNull String s) { // null? no problem } @@ -96,8 +96,7 @@ public static void staticOneArgNullableCorrectlyDoesNotThrowNPE(@Nullable String // null? no problem } - public static void staticOneArgCheckForNullCorrectlyThrowsOtherThanNPE( - @javax.annotation.CheckForNull String s) { + public static void staticOneArgCheckForNullCorrectlyThrowsOtherThanNPE(@CheckForNull String s) { throw new FooException(); // ok, as long as it's not NullPointerException } @@ -105,7 +104,7 @@ public static void staticOneArgNullableCorrectlyThrowsOtherThanNPE(@Nullable Str throw new FooException(); // ok, as long as it's not NullPointerException } - public static void staticOneArgCheckForNullThrowsNPE(@javax.annotation.CheckForNull String s) { + public static void staticOneArgCheckForNullThrowsNPE(@CheckForNull String s) { checkNotNull(s); // doesn't check if you said you'd accept null, but you don't } @@ -125,8 +124,7 @@ public void oneArgShouldThrowNpeButDoesnt(String s) { // should catch as failure } - public void oneArgCheckForNullCorrectlyDoesNotThrowNPE( - @javax.annotation.CheckForNull String s) { + public void oneArgCheckForNullCorrectlyDoesNotThrowNPE(@CheckForNull String s) { // null? no problem } @@ -134,8 +132,7 @@ public void oneArgNullableCorrectlyDoesNotThrowNPE(@Nullable String s) { // null? no problem } - public void oneArgCheckForNullCorrectlyThrowsOtherThanNPE( - @javax.annotation.CheckForNull String s) { + public void oneArgCheckForNullCorrectlyThrowsOtherThanNPE(@CheckForNull String s) { throw new FooException(); // ok, as long as it's not NullPointerException } @@ -143,7 +140,7 @@ public void oneArgNullableCorrectlyThrowsOtherThanNPE(@Nullable String s) { throw new FooException(); // ok, as long as it's not NullPointerException } - public void oneArgCheckForNullThrowsNPE(@javax.annotation.CheckForNull String s) { + public void oneArgCheckForNullThrowsNPE(@CheckForNull String s) { checkNotNull(s); // doesn't check if you said you'd accept null, but you don't } diff --git a/guava-tests/benchmark/com/google/common/util/concurrent/ExecutionListBenchmark.java b/guava-tests/benchmark/com/google/common/util/concurrent/ExecutionListBenchmark.java index d1c2dfade8ec..b866336b84a8 100644 --- a/guava-tests/benchmark/com/google/common/util/concurrent/ExecutionListBenchmark.java +++ b/guava-tests/benchmark/com/google/common/util/concurrent/ExecutionListBenchmark.java @@ -28,6 +28,10 @@ import com.google.common.collect.Lists; import com.google.common.util.concurrent.AbstractFutureBenchmarks.OldAbstractFuture; import com.google.errorprone.annotations.concurrent.GuardedBy; +import java.lang.reflect.Field; +import java.security.AccessController; +import java.security.PrivilegedActionException; +import java.security.PrivilegedExceptionAction; import java.util.Queue; import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.CountDownLatch; @@ -39,6 +43,7 @@ import java.util.logging.Level; import java.util.logging.Logger; import org.checkerframework.checker.nullness.qual.Nullable; +import sun.misc.Unsafe; /** Benchmarks for {@link ExecutionList}. */ @VmOptions({"-Xms8g", "-Xmx8g"}) @@ -577,7 +582,7 @@ private static final class RunnableExecutorPair { private static final class ExecutionListCAS { static final Logger log = Logger.getLogger(ExecutionListCAS.class.getName()); - private static final sun.misc.Unsafe UNSAFE; + private static final Unsafe UNSAFE; private static final long HEAD_OFFSET; /** @@ -596,18 +601,18 @@ private static final class ExecutionListCAS { } /** TODO(lukes): This was copied verbatim from Striped64.java... standardize this? */ - private static sun.misc.Unsafe getUnsafe() { + private static Unsafe getUnsafe() { try { - return sun.misc.Unsafe.getUnsafe(); + return Unsafe.getUnsafe(); } catch (SecurityException tryReflectionInstead) { } try { - return java.security.AccessController.doPrivileged( - new java.security.PrivilegedExceptionAction() { + return AccessController.doPrivileged( + new PrivilegedExceptionAction() { @Override - public sun.misc.Unsafe run() throws Exception { - Class k = sun.misc.Unsafe.class; - for (java.lang.reflect.Field f : k.getDeclaredFields()) { + public Unsafe run() throws Exception { + Class k = Unsafe.class; + for (Field f : k.getDeclaredFields()) { f.setAccessible(true); Object x = f.get(null); if (k.isInstance(x)) return k.cast(x); @@ -615,7 +620,7 @@ public sun.misc.Unsafe run() throws Exception { throw new NoSuchFieldError("the Unsafe"); } }); - } catch (java.security.PrivilegedActionException e) { + } catch (PrivilegedActionException e) { throw new RuntimeException("Could not initialize intrinsics", e.getCause()); } } diff --git a/guava-tests/test/com/google/common/base/SuppliersTest.java b/guava-tests/test/com/google/common/base/SuppliersTest.java index 04c837d78205..1954c164c076 100644 --- a/guava-tests/test/com/google/common/base/SuppliersTest.java +++ b/guava-tests/test/com/google/common/base/SuppliersTest.java @@ -26,6 +26,7 @@ import com.google.common.collect.Lists; import com.google.common.testing.ClassSanityTester; import com.google.common.testing.EqualsTester; +import java.io.NotSerializableException; import java.io.Serializable; import java.time.Duration; import java.util.ArrayList; @@ -145,7 +146,7 @@ public void testMemoizeNonSerializable() throws Exception { // Should get an exception when we try to serialize. RuntimeException ex = assertThrows(RuntimeException.class, () -> reserialize(memoizedSupplier)); - assertThat(ex).hasCauseThat().isInstanceOf(java.io.NotSerializableException.class); + assertThat(ex).hasCauseThat().isInstanceOf(NotSerializableException.class); } @J2ktIncompatible diff --git a/guava-tests/test/com/google/common/reflect/ClassPathTest.java b/guava-tests/test/com/google/common/reflect/ClassPathTest.java index 1357d00e0dc8..e1ddb4e29652 100644 --- a/guava-tests/test/com/google/common/reflect/ClassPathTest.java +++ b/guava-tests/test/com/google/common/reflect/ClassPathTest.java @@ -47,6 +47,7 @@ import java.net.URISyntaxException; import java.net.URL; import java.net.URLClassLoader; +import java.nio.file.Path; import java.security.Permission; import java.security.PermissionCollection; import java.util.jar.Attributes; @@ -213,12 +214,12 @@ public void testScanDirectory_symlinkCycle() throws IOException { // /[sibling -> right] // /right // /[sibling -> left] - java.nio.file.Path root = createTempDirectory("ClassPathTest"); + Path root = createTempDirectory("ClassPathTest"); try { - java.nio.file.Path left = createDirectory(root.resolve("left")); + Path left = createDirectory(root.resolve("left")); createFile(left.resolve("some.txt")); - java.nio.file.Path right = createDirectory(root.resolve("right")); + Path right = createDirectory(root.resolve("right")); createFile(right.resolve("another.txt")); createSymbolicLink(left.resolve("sibling"), right); @@ -246,10 +247,10 @@ public void testScanDirectory_symlinkToRootCycle() throws IOException { // /root // /child // /[grandchild -> root] - java.nio.file.Path root = createTempDirectory("ClassPathTest"); + Path root = createTempDirectory("ClassPathTest"); try { createFile(root.resolve("some.txt")); - java.nio.file.Path child = createDirectory(root.resolve("child")); + Path child = createDirectory(root.resolve("child")); createSymbolicLink(child.resolve("grandchild"), root); assertEquals( ImmutableSet.of(new ResourceInfo(FILE, "some.txt", loader)), @@ -650,7 +651,7 @@ private static File pickAnyJarFile() throws IOException { } @AndroidIncompatible // Path (for symlink creation) - private static void deleteRecursivelyOrLog(java.nio.file.Path path) { + private static void deleteRecursivelyOrLog(Path path) { try { deleteRecursively(path); } catch (IOException e) { diff --git a/guava-tests/test/com/google/common/util/concurrent/AbstractFutureFallbackAtomicHelperTest.java b/guava-tests/test/com/google/common/util/concurrent/AbstractFutureFallbackAtomicHelperTest.java index 0bcb6adf56c4..42cb8a1fbecc 100644 --- a/guava-tests/test/com/google/common/util/concurrent/AbstractFutureFallbackAtomicHelperTest.java +++ b/guava-tests/test/com/google/common/util/concurrent/AbstractFutureFallbackAtomicHelperTest.java @@ -23,6 +23,7 @@ import java.util.concurrent.atomic.AtomicReferenceFieldUpdater; import junit.framework.TestCase; import junit.framework.TestSuite; +import sun.misc.Unsafe; /** * Tests our AtomicHelper fallback strategies in AbstractFuture. @@ -55,7 +56,7 @@ public class AbstractFutureFallbackAtomicHelperTest extends TestCase { */ @SuppressWarnings({"SunApi", "removal"}) // b/345822163 private static final ClassLoader NO_UNSAFE = - getClassLoader(ImmutableSet.of(sun.misc.Unsafe.class.getName())); + getClassLoader(ImmutableSet.of(Unsafe.class.getName())); /** * This classloader disallows {@link sun.misc.Unsafe} and {@link AtomicReferenceFieldUpdater}, @@ -64,8 +65,7 @@ public class AbstractFutureFallbackAtomicHelperTest extends TestCase { @SuppressWarnings({"SunApi", "removal"}) // b/345822163 private static final ClassLoader NO_ATOMIC_REFERENCE_FIELD_UPDATER = getClassLoader( - ImmutableSet.of( - sun.misc.Unsafe.class.getName(), AtomicReferenceFieldUpdater.class.getName())); + ImmutableSet.of(Unsafe.class.getName(), AtomicReferenceFieldUpdater.class.getName())); public static TestSuite suite() { // we create a test suite containing a test for every AbstractFutureTest test method and we diff --git a/guava-tests/test/com/google/common/util/concurrent/JSR166TestCase.java b/guava-tests/test/com/google/common/util/concurrent/JSR166TestCase.java index 3d72790a7dc5..645af76f3f4e 100644 --- a/guava-tests/test/com/google/common/util/concurrent/JSR166TestCase.java +++ b/guava-tests/test/com/google/common/util/concurrent/JSR166TestCase.java @@ -20,6 +20,7 @@ import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; +import java.io.FilePermission; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.security.CodeSource; @@ -590,7 +591,7 @@ public void runWithoutPermissions(Runnable r) { } /** A security policy where new permissions can be dynamically added or all cleared. */ - public static class AdjustablePolicy extends java.security.Policy { + public static class AdjustablePolicy extends Policy { Permissions perms = new Permissions(); AdjustablePolicy(Permission... permissions) { @@ -639,7 +640,7 @@ public static Policy permissivePolicy() { // Permissions needed by the junit test harness new RuntimePermission("accessDeclaredMembers"), new PropertyPermission("*", "read"), - new java.io.FilePermission("<>", "read")); + new FilePermission("<>", "read")); } /** Sleeps until the given time has elapsed. Throws AssertionFailedError if interrupted. */ diff --git a/guava/src/com/google/common/cache/Striped64.java b/guava/src/com/google/common/cache/Striped64.java index ab05853281e3..e8be86e36e5d 100644 --- a/guava/src/com/google/common/cache/Striped64.java +++ b/guava/src/com/google/common/cache/Striped64.java @@ -12,9 +12,14 @@ package com.google.common.cache; import com.google.common.annotations.GwtIncompatible; +import java.lang.reflect.Field; +import java.security.AccessController; +import java.security.PrivilegedActionException; +import java.security.PrivilegedExceptionAction; import java.util.Random; import javax.annotation.CheckForNull; import org.checkerframework.checker.nullness.qual.Nullable; +import sun.misc.Unsafe; /** * A package-local class holding common representation and mechanics for classes supporting dynamic @@ -109,7 +114,7 @@ final boolean cas(long cmp, long val) { } // Unsafe mechanics - private static final sun.misc.Unsafe UNSAFE; + private static final Unsafe UNSAFE; private static final long valueOffset; static { @@ -267,7 +272,7 @@ final void internalReset(long initialValue) { } // Unsafe mechanics - private static final sun.misc.Unsafe UNSAFE; + private static final Unsafe UNSAFE; private static final long baseOffset; private static final long busyOffset; @@ -288,18 +293,18 @@ final void internalReset(long initialValue) { * * @return a sun.misc.Unsafe */ - private static sun.misc.Unsafe getUnsafe() { + private static Unsafe getUnsafe() { try { - return sun.misc.Unsafe.getUnsafe(); + return Unsafe.getUnsafe(); } catch (SecurityException tryReflectionInstead) { } try { - return java.security.AccessController.doPrivileged( - new java.security.PrivilegedExceptionAction() { + return AccessController.doPrivileged( + new PrivilegedExceptionAction() { @Override - public sun.misc.Unsafe run() throws Exception { - Class k = sun.misc.Unsafe.class; - for (java.lang.reflect.Field f : k.getDeclaredFields()) { + public Unsafe run() throws Exception { + Class k = Unsafe.class; + for (Field f : k.getDeclaredFields()) { f.setAccessible(true); Object x = f.get(null); if (k.isInstance(x)) return k.cast(x); @@ -307,7 +312,7 @@ public sun.misc.Unsafe run() throws Exception { throw new NoSuchFieldError("the Unsafe"); } }); - } catch (java.security.PrivilegedActionException e) { + } catch (PrivilegedActionException e) { throw new RuntimeException("Could not initialize intrinsics", e.getCause()); } } diff --git a/guava/src/com/google/common/collect/ForwardingNavigableMap.java b/guava/src/com/google/common/collect/ForwardingNavigableMap.java index 4cc10b57fede..292f4573b6b4 100644 --- a/guava/src/com/google/common/collect/ForwardingNavigableMap.java +++ b/guava/src/com/google/common/collect/ForwardingNavigableMap.java @@ -326,7 +326,7 @@ public boolean hasNext() { } @Override - public java.util.Map.Entry next() { + public Entry next() { if (nextOrNull == null) { throw new NoSuchElementException(); } diff --git a/guava/src/com/google/common/collect/Queues.java b/guava/src/com/google/common/collect/Queues.java index 0123b531e503..e6cf8d6e30e5 100644 --- a/guava/src/com/google/common/collect/Queues.java +++ b/guava/src/com/google/common/collect/Queues.java @@ -19,6 +19,7 @@ import com.google.common.annotations.J2ktIncompatible; import com.google.common.base.Preconditions; import com.google.errorprone.annotations.CanIgnoreReturnValue; +import java.time.Duration; import java.util.ArrayDeque; import java.util.Collection; import java.util.Deque; @@ -290,7 +291,7 @@ public static SynchronousQueue newSynchronousQueue() { @J2ktIncompatible @GwtIncompatible // BlockingQueue public static int drain( - BlockingQueue q, Collection buffer, int numElements, java.time.Duration timeout) + BlockingQueue q, Collection buffer, int numElements, Duration timeout) throws InterruptedException { // TODO(b/126049426): Consider using saturateToNanos(timeout) instead. return drain(q, buffer, numElements, timeout.toNanos(), TimeUnit.NANOSECONDS); @@ -360,10 +361,7 @@ public static int drain( @J2ktIncompatible @GwtIncompatible // BlockingQueue public static int drainUninterruptibly( - BlockingQueue q, - Collection buffer, - int numElements, - java.time.Duration timeout) { + BlockingQueue q, Collection buffer, int numElements, Duration timeout) { // TODO(b/126049426): Consider using saturateToNanos(timeout) instead. return drainUninterruptibly(q, buffer, numElements, timeout.toNanos(), TimeUnit.NANOSECONDS); } diff --git a/guava/src/com/google/common/collect/TableCollectors.java b/guava/src/com/google/common/collect/TableCollectors.java index ca67a693aec4..b052f3157729 100644 --- a/guava/src/com/google/common/collect/TableCollectors.java +++ b/guava/src/com/google/common/collect/TableCollectors.java @@ -86,10 +86,10 @@ final class TableCollectors { V, I extends Table> Collector toTable( - java.util.function.Function rowFunction, - java.util.function.Function columnFunction, - java.util.function.Function valueFunction, - java.util.function.Supplier tableSupplier) { + Function rowFunction, + Function columnFunction, + Function valueFunction, + Supplier tableSupplier) { return TableCollectors.toTable( rowFunction, columnFunction, @@ -107,11 +107,11 @@ final class TableCollectors { V, I extends Table> Collector toTable( - java.util.function.Function rowFunction, - java.util.function.Function columnFunction, - java.util.function.Function valueFunction, + Function rowFunction, + Function columnFunction, + Function valueFunction, BinaryOperator mergeFunction, - java.util.function.Supplier tableSupplier) { + Supplier tableSupplier) { checkNotNull(rowFunction); checkNotNull(columnFunction); checkNotNull(valueFunction); diff --git a/guava/src/com/google/common/hash/BloomFilter.java b/guava/src/com/google/common/hash/BloomFilter.java index d9a1c53bee9e..3b041effb3c5 100644 --- a/guava/src/com/google/common/hash/BloomFilter.java +++ b/guava/src/com/google/common/hash/BloomFilter.java @@ -75,7 +75,7 @@ public final class BloomFilter implements Predicate< * *

Implementations should be collections of pure functions (i.e. stateless). */ - interface Strategy extends java.io.Serializable { + interface Strategy extends Serializable { /** * Sets {@code numHashFunctions} bits of the given bit array, by hashing a user element. diff --git a/guava/src/com/google/common/hash/Striped64.java b/guava/src/com/google/common/hash/Striped64.java index df6914731dc0..6cbbd7f5aa80 100644 --- a/guava/src/com/google/common/hash/Striped64.java +++ b/guava/src/com/google/common/hash/Striped64.java @@ -12,9 +12,14 @@ package com.google.common.hash; import com.google.common.annotations.GwtIncompatible; +import java.lang.reflect.Field; +import java.security.AccessController; +import java.security.PrivilegedActionException; +import java.security.PrivilegedExceptionAction; import java.util.Random; import javax.annotation.CheckForNull; import org.checkerframework.checker.nullness.qual.Nullable; +import sun.misc.Unsafe; /** * A package-local class holding common representation and mechanics for classes supporting dynamic @@ -109,7 +114,7 @@ final boolean cas(long cmp, long val) { } // Unsafe mechanics - private static final sun.misc.Unsafe UNSAFE; + private static final Unsafe UNSAFE; private static final long valueOffset; static { @@ -267,7 +272,7 @@ final void internalReset(long initialValue) { } // Unsafe mechanics - private static final sun.misc.Unsafe UNSAFE; + private static final Unsafe UNSAFE; private static final long baseOffset; private static final long busyOffset; @@ -288,18 +293,18 @@ final void internalReset(long initialValue) { * * @return a sun.misc.Unsafe */ - private static sun.misc.Unsafe getUnsafe() { + private static Unsafe getUnsafe() { try { - return sun.misc.Unsafe.getUnsafe(); + return Unsafe.getUnsafe(); } catch (SecurityException tryReflectionInstead) { } try { - return java.security.AccessController.doPrivileged( - new java.security.PrivilegedExceptionAction() { + return AccessController.doPrivileged( + new PrivilegedExceptionAction() { @Override - public sun.misc.Unsafe run() throws Exception { - Class k = sun.misc.Unsafe.class; - for (java.lang.reflect.Field f : k.getDeclaredFields()) { + public Unsafe run() throws Exception { + Class k = Unsafe.class; + for (Field f : k.getDeclaredFields()) { f.setAccessible(true); Object x = f.get(null); if (k.isInstance(x)) return k.cast(x); @@ -307,7 +312,7 @@ public sun.misc.Unsafe run() throws Exception { throw new NoSuchFieldError("the Unsafe"); } }); - } catch (java.security.PrivilegedActionException e) { + } catch (PrivilegedActionException e) { throw new RuntimeException("Could not initialize intrinsics", e.getCause()); } } diff --git a/guava/src/com/google/common/primitives/UnsignedBytes.java b/guava/src/com/google/common/primitives/UnsignedBytes.java index 739125ff9786..75e0266047a0 100644 --- a/guava/src/com/google/common/primitives/UnsignedBytes.java +++ b/guava/src/com/google/common/primitives/UnsignedBytes.java @@ -23,7 +23,11 @@ import com.google.common.annotations.J2ktIncompatible; import com.google.common.annotations.VisibleForTesting; import com.google.errorprone.annotations.CanIgnoreReturnValue; +import java.lang.reflect.Field; import java.nio.ByteOrder; +import java.security.AccessController; +import java.security.PrivilegedActionException; +import java.security.PrivilegedExceptionAction; import java.util.Arrays; import java.util.Comparator; import sun.misc.Unsafe; @@ -334,19 +338,19 @@ enum UnsafeComparator implements Comparator { * * @return a sun.misc.Unsafe */ - private static sun.misc.Unsafe getUnsafe() { + private static Unsafe getUnsafe() { try { - return sun.misc.Unsafe.getUnsafe(); + return Unsafe.getUnsafe(); } catch (SecurityException e) { // that's okay; try reflection instead } try { - return java.security.AccessController.doPrivileged( - new java.security.PrivilegedExceptionAction() { + return AccessController.doPrivileged( + new PrivilegedExceptionAction() { @Override - public sun.misc.Unsafe run() throws Exception { - Class k = sun.misc.Unsafe.class; - for (java.lang.reflect.Field f : k.getDeclaredFields()) { + public Unsafe run() throws Exception { + Class k = Unsafe.class; + for (Field f : k.getDeclaredFields()) { f.setAccessible(true); Object x = f.get(null); if (k.isInstance(x)) { @@ -356,7 +360,7 @@ public sun.misc.Unsafe run() throws Exception { throw new NoSuchFieldError("the Unsafe"); } }); - } catch (java.security.PrivilegedActionException e) { + } catch (PrivilegedActionException e) { throw new RuntimeException("Could not initialize intrinsics", e.getCause()); } } diff --git a/guava/src/com/google/common/reflect/MutableTypeToInstanceMap.java b/guava/src/com/google/common/reflect/MutableTypeToInstanceMap.java index 7690d2eef928..5e95e22633f5 100644 --- a/guava/src/com/google/common/reflect/MutableTypeToInstanceMap.java +++ b/guava/src/com/google/common/reflect/MutableTypeToInstanceMap.java @@ -162,7 +162,7 @@ public Object[] toArray() { return Iterators.transform(entries, UnmodifiableEntry::new); } - private UnmodifiableEntry(java.util.Map.Entry delegate) { + private UnmodifiableEntry(Entry delegate) { this.delegate = checkNotNull(delegate); } diff --git a/guava/src/com/google/common/util/concurrent/AbstractFuture.java b/guava/src/com/google/common/util/concurrent/AbstractFuture.java index 0506bded1cde..7a207fb57eb9 100644 --- a/guava/src/com/google/common/util/concurrent/AbstractFuture.java +++ b/guava/src/com/google/common/util/concurrent/AbstractFuture.java @@ -28,6 +28,7 @@ import com.google.errorprone.annotations.CanIgnoreReturnValue; import com.google.errorprone.annotations.ForOverride; import com.google.j2objc.annotations.ReflectionSupport; +import java.lang.reflect.Field; import java.security.AccessController; import java.security.PrivilegedActionException; import java.security.PrivilegedExceptionAction; @@ -44,6 +45,7 @@ import java.util.logging.Level; import javax.annotation.CheckForNull; import org.checkerframework.checker.nullness.qual.Nullable; +import sun.misc.Unsafe; /** * An abstract implementation of {@link ListenableFuture}, intended for advanced users only. More @@ -1343,7 +1345,7 @@ abstract boolean casListeners( */ @SuppressWarnings({"SunApi", "removal"}) // b/345822163 private static final class UnsafeAtomicHelper extends AtomicHelper { - static final sun.misc.Unsafe UNSAFE; + static final Unsafe UNSAFE; static final long LISTENERS_OFFSET; static final long WAITERS_OFFSET; static final long VALUE_OFFSET; @@ -1351,18 +1353,18 @@ private static final class UnsafeAtomicHelper extends AtomicHelper { static final long WAITER_NEXT_OFFSET; static { - sun.misc.Unsafe unsafe = null; + Unsafe unsafe = null; try { - unsafe = sun.misc.Unsafe.getUnsafe(); + unsafe = Unsafe.getUnsafe(); } catch (SecurityException tryReflectionInstead) { try { unsafe = AccessController.doPrivileged( - new PrivilegedExceptionAction() { + new PrivilegedExceptionAction() { @Override - public sun.misc.Unsafe run() throws Exception { - Class k = sun.misc.Unsafe.class; - for (java.lang.reflect.Field f : k.getDeclaredFields()) { + public Unsafe run() throws Exception { + Class k = Unsafe.class; + for (Field f : k.getDeclaredFields()) { f.setAccessible(true); Object x = f.get(null); if (k.isInstance(x)) { diff --git a/guava/src/com/google/common/util/concurrent/AtomicDouble.java b/guava/src/com/google/common/util/concurrent/AtomicDouble.java index 7e3cb23039ae..0565da7b8560 100644 --- a/guava/src/com/google/common/util/concurrent/AtomicDouble.java +++ b/guava/src/com/google/common/util/concurrent/AtomicDouble.java @@ -22,6 +22,10 @@ import com.google.common.annotations.J2ktIncompatible; import com.google.errorprone.annotations.CanIgnoreReturnValue; import com.google.j2objc.annotations.ReflectionSupport; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.io.Serializable; import java.util.concurrent.atomic.AtomicLongFieldUpdater; import java.util.function.DoubleBinaryOperator; import java.util.function.DoubleUnaryOperator; @@ -59,7 +63,7 @@ @J2ktIncompatible @ReflectionSupport(value = ReflectionSupport.Level.FULL) @ElementTypesAreNonnullByDefault -public class AtomicDouble extends Number implements java.io.Serializable { +public class AtomicDouble extends Number implements Serializable { private static final long serialVersionUID = 0L; private transient volatile long value; @@ -292,15 +296,14 @@ public double doubleValue() { * * @serialData The current value is emitted (a {@code double}). */ - private void writeObject(java.io.ObjectOutputStream s) throws java.io.IOException { + private void writeObject(ObjectOutputStream s) throws IOException { s.defaultWriteObject(); s.writeDouble(get()); } /** Reconstitutes the instance from a stream (that is, deserializes it). */ - private void readObject(java.io.ObjectInputStream s) - throws java.io.IOException, ClassNotFoundException { + private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException { s.defaultReadObject(); set(s.readDouble()); diff --git a/guava/src/com/google/common/util/concurrent/AtomicDoubleArray.java b/guava/src/com/google/common/util/concurrent/AtomicDoubleArray.java index 6f88671893a0..3f67671de770 100644 --- a/guava/src/com/google/common/util/concurrent/AtomicDoubleArray.java +++ b/guava/src/com/google/common/util/concurrent/AtomicDoubleArray.java @@ -21,6 +21,10 @@ import com.google.common.annotations.J2ktIncompatible; import com.google.common.primitives.ImmutableLongArray; import com.google.errorprone.annotations.CanIgnoreReturnValue; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.io.Serializable; import java.util.concurrent.atomic.AtomicLongArray; import java.util.function.DoubleBinaryOperator; import java.util.function.DoubleUnaryOperator; @@ -50,7 +54,7 @@ @GwtIncompatible @J2ktIncompatible @ElementTypesAreNonnullByDefault -public class AtomicDoubleArray implements java.io.Serializable { +public class AtomicDoubleArray implements Serializable { private static final long serialVersionUID = 0L; // Making this non-final is the lesser evil according to Effective @@ -297,7 +301,7 @@ public String toString() { * @serialData The length of the array is emitted (int), followed by all of its elements (each a * {@code double}) in the proper order. */ - private void writeObject(java.io.ObjectOutputStream s) throws java.io.IOException { + private void writeObject(ObjectOutputStream s) throws IOException { s.defaultWriteObject(); // Write out array length @@ -311,8 +315,7 @@ private void writeObject(java.io.ObjectOutputStream s) throws java.io.IOExceptio } /** Reconstitutes the instance from a stream (that is, deserializes it). */ - private void readObject(java.io.ObjectInputStream s) - throws java.io.IOException, ClassNotFoundException { + private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException { s.defaultReadObject(); int length = s.readInt();