diff options
author | ZHANG Dapeng <zdapeng@google.com> | 2018-05-15 13:14:30 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-05-15 13:14:30 -0700 |
commit | bf4a00c6deac7c3526ac37163aada94e8b9bf38f (patch) | |
tree | e1f309367fa829b495945c2ab0851935e0d572c0 /context | |
parent | 561583be1476e54f37812246329be43470262a55 (diff) | |
download | grpc-grpc-java-bf4a00c6deac7c3526ac37163aada94e8b9bf38f.tar.gz |
context/core/netty: Add @CheckReturnValue to Context
By adding inner class annotations without introducing external dependencies.
Diffstat (limited to 'context')
-rw-r--r-- | context/src/main/java/io/grpc/Context.java | 11 | ||||
-rw-r--r-- | context/src/test/java/io/grpc/ContextTest.java | 1 |
2 files changed, 12 insertions, 0 deletions
diff --git a/context/src/main/java/io/grpc/Context.java b/context/src/main/java/io/grpc/Context.java index 795eb4ec3..0e76c08e1 100644 --- a/context/src/main/java/io/grpc/Context.java +++ b/context/src/main/java/io/grpc/Context.java @@ -16,6 +16,7 @@ package io.grpc; +import io.grpc.Context.CheckReturnValue; import java.io.Closeable; import java.util.ArrayList; import java.util.concurrent.Callable; @@ -93,6 +94,7 @@ import java.util.logging.Logger; * </ul> */ /* @DoNotMock("Use ROOT for a non-null Context") // commented out to avoid dependencies */ +@CheckReturnValue public class Context { private static final Logger log = Logger.getLogger(Context.class.getName()); @@ -571,6 +573,7 @@ public class Context { * @param c {@link Callable} to call. * @return result of call. */ + @CanIgnoreReturnValue public <V> V call(Callable<V> c) throws Exception { Context previous = attach(); try { @@ -776,6 +779,7 @@ public class Context { * @return {@code true} if this context cancelled the context and notified listeners, * {@code false} if the context was already cancelled. */ + @CanIgnoreReturnValue public boolean cancel(Throwable cause) { boolean triggeredCancel = false; synchronized (this) { @@ -1008,6 +1012,7 @@ public class Context { } } + @CanIgnoreReturnValue private static <T> T checkNotNull(T reference, Object errorMessage) { if (reference == null) { throw new NullPointerException(String.valueOf(errorMessage)); @@ -1059,4 +1064,10 @@ public class Context { new Exception()); } } + + // Not using the standard com.google.errorprone.annotations.CheckReturnValue because that will + // introduce dependencies that some io.grpc.Context API consumers may not want. + @interface CheckReturnValue {} + + @interface CanIgnoreReturnValue {} } diff --git a/context/src/test/java/io/grpc/ContextTest.java b/context/src/test/java/io/grpc/ContextTest.java index ab0130bf7..c0b8f9697 100644 --- a/context/src/test/java/io/grpc/ContextTest.java +++ b/context/src/test/java/io/grpc/ContextTest.java @@ -60,6 +60,7 @@ import org.junit.runners.JUnit4; * Tests for {@link Context}. */ @RunWith(JUnit4.class) +@SuppressWarnings("CheckReturnValue") // false-positive in test for current ver errorprone plugin public class ContextTest { private static final Context.Key<String> PET = Context.key("pet"); |