From 429911376e17291212b364cb6e829d0302399c5f Mon Sep 17 00:00:00 2001 From: Damon Douglas Date: Sun, 9 Jul 2023 12:46:52 -0700 Subject: [PATCH 1/2] Remove SuppressWarnings from NoopLock.java --- .../java/org/apache/beam/sdk/util/NoopLock.java | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/sdks/java/core/src/main/java/org/apache/beam/sdk/util/NoopLock.java b/sdks/java/core/src/main/java/org/apache/beam/sdk/util/NoopLock.java index 0fc822987a6e..528b9e1a3fd6 100644 --- a/sdks/java/core/src/main/java/org/apache/beam/sdk/util/NoopLock.java +++ b/sdks/java/core/src/main/java/org/apache/beam/sdk/util/NoopLock.java @@ -21,19 +21,17 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.locks.Condition; import java.util.concurrent.locks.Lock; -import javax.annotation.Nonnull; +import org.checkerframework.checker.nullness.qual.NonNull; +import org.checkerframework.checker.nullness.qual.Nullable; /** * A lock which can always be acquired. It should not be used when a proper lock is required, but it * is useful as a performance optimization when locking is not necessary but the code paths have to * be shared between the locking and the non-locking variant. */ -@SuppressWarnings({ - "nullness" // TODO(https://github.com/apache/beam/issues/20497) -}) public class NoopLock implements Lock, Serializable { - private static NoopLock instance; + private static @Nullable NoopLock instance; public static NoopLock get() { if (instance == null) { @@ -56,16 +54,15 @@ public boolean tryLock() { } @Override - public boolean tryLock(long time, @Nonnull TimeUnit unit) { + public boolean tryLock(long time, @NonNull TimeUnit unit) { return true; } @Override public void unlock() {} - @Nonnull @Override - public Condition newCondition() { + public @NonNull Condition newCondition() { throw new UnsupportedOperationException("Not implemented"); } } From 481324c333225f1447ec72d15a9cd67bc60f8586 Mon Sep 17 00:00:00 2001 From: Damon Douglas Date: Sun, 16 Jul 2023 13:09:36 -0700 Subject: [PATCH 2/2] Remove Nonnull annotations from original --- .../main/java/org/apache/beam/sdk/util/NoopLock.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/sdks/java/core/src/main/java/org/apache/beam/sdk/util/NoopLock.java b/sdks/java/core/src/main/java/org/apache/beam/sdk/util/NoopLock.java index 528b9e1a3fd6..36454a125d67 100644 --- a/sdks/java/core/src/main/java/org/apache/beam/sdk/util/NoopLock.java +++ b/sdks/java/core/src/main/java/org/apache/beam/sdk/util/NoopLock.java @@ -21,8 +21,8 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.locks.Condition; import java.util.concurrent.locks.Lock; +import org.checkerframework.checker.nullness.qual.MonotonicNonNull; import org.checkerframework.checker.nullness.qual.NonNull; -import org.checkerframework.checker.nullness.qual.Nullable; /** * A lock which can always be acquired. It should not be used when a proper lock is required, but it @@ -31,9 +31,9 @@ */ public class NoopLock implements Lock, Serializable { - private static @Nullable NoopLock instance; + private static @MonotonicNonNull NoopLock instance; - public static NoopLock get() { + public static @NonNull NoopLock get() { if (instance == null) { instance = new NoopLock(); } @@ -54,7 +54,7 @@ public boolean tryLock() { } @Override - public boolean tryLock(long time, @NonNull TimeUnit unit) { + public boolean tryLock(long time, TimeUnit unit) { return true; } @@ -62,7 +62,7 @@ public boolean tryLock(long time, @NonNull TimeUnit unit) { public void unlock() {} @Override - public @NonNull Condition newCondition() { + public Condition newCondition() { throw new UnsupportedOperationException("Not implemented"); } }