From 83634a50fe60c221a19f79e4735ac65467c21983 Mon Sep 17 00:00:00 2001 From: Chaoren Lin Date: Fri, 13 Dec 2024 11:00:23 -0800 Subject: [PATCH] Mark `java.time.InstantSource` and `java.time.Clock` as thread safe. Also, annotate `FakeTimeSource` with `@ThreadSafe` to fix breakages caused by marking `InstantSource` as thread safe. `TimeSource` and `common.time.Clock` should also be annotated directly, but we would need to fix or suppress all existing implementations of them first, so I left a TODO instead. Context: http://yaqs/6914049073339170816 Tested: TAP for global presubmit queue [] PiperOrigin-RevId: 705936781 --- .../bugpatterns/threadsafety/WellKnownThreadSafety.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/threadsafety/WellKnownThreadSafety.java b/core/src/main/java/com/google/errorprone/bugpatterns/threadsafety/WellKnownThreadSafety.java index 41e1b070fdf..345e416e9bb 100644 --- a/core/src/main/java/com/google/errorprone/bugpatterns/threadsafety/WellKnownThreadSafety.java +++ b/core/src/main/java/com/google/errorprone/bugpatterns/threadsafety/WellKnownThreadSafety.java @@ -63,8 +63,10 @@ private static ImmutableMap buildThreadSafeClasses( new MapBuilder() .addAll(mutability.getKnownImmutableClasses()) .addStrings(extraKnownThreadSafe) - .add(ClassLoader.class) - .add(Thread.class) + .add(java.lang.ClassLoader.class) + .add(java.lang.Thread.class) + .add(java.time.InstantSource.class) + .add(java.time.Clock.class) .add(java.util.Random.class) .add(java.util.concurrent.atomic.AtomicBoolean.class) .add(java.util.concurrent.atomic.AtomicInteger.class) @@ -108,8 +110,6 @@ private static ImmutableMap buildThreadSafeClasses( .add(java.security.SecureRandom.class) .add("com.google.common.base.Ticker") .add("com.google.common.testing.FakeTicker") - .add("com.google.common.time.Clock") - .add("com.google.common.time.TimeSource") .add("com.google.common.util.concurrent.AtomicLongMap", "K") .add("com.google.common.util.concurrent.CheckedFuture", "V", "X") .add("com.google.common.util.concurrent.ListeningExecutorService")