all: add parameter name to checkNotNull

After debugging #2153, it would have been nice to know what the exact
parameter was that was null. This change adds a name for each
checkNotNull (and tries to normalized on static imports in order to
shorten lines)
This commit is contained in:
Carl Mastrangelo 2016-08-12 14:52:00 -07:00
parent 55942fbd37
commit 1285477133
37 changed files with 77 additions and 76 deletions

View File

@ -70,7 +70,7 @@ public final class ClientAuthInterceptor implements ClientInterceptor {
public ClientAuthInterceptor( public ClientAuthInterceptor(
Credentials credentials, @SuppressWarnings("unused") Executor executor) { Credentials credentials, @SuppressWarnings("unused") Executor executor) {
this.credentials = Preconditions.checkNotNull(credentials); this.credentials = Preconditions.checkNotNull(credentials, "credentials");
// TODO(louiscryan): refresh token asynchronously with this executor. // TODO(louiscryan): refresh token asynchronously with this executor.
} }

View File

@ -183,7 +183,7 @@ public final class CallOptions {
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/1766") @ExperimentalApi("https://github.com/grpc/grpc-java/issues/1766")
public CallOptions withAffinity(Attributes affinity) { public CallOptions withAffinity(Attributes affinity) {
CallOptions newOptions = new CallOptions(this); CallOptions newOptions = new CallOptions(this);
newOptions.affinity = Preconditions.checkNotNull(affinity); newOptions.affinity = Preconditions.checkNotNull(affinity, "affinity");
return newOptions; return newOptions;
} }
@ -289,7 +289,7 @@ public final class CallOptions {
* @return Key object * @return Key object
*/ */
public static <T> Key<T> of(String name, T defaultValue) { public static <T> Key<T> of(String name, T defaultValue) {
Preconditions.checkNotNull(name); Preconditions.checkNotNull(name, "name");
return new Key<T>(name, defaultValue); return new Key<T>(name, defaultValue);
} }
} }
@ -302,8 +302,8 @@ public final class CallOptions {
*/ */
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/1869") @ExperimentalApi("https://github.com/grpc/grpc-java/issues/1869")
public <T> CallOptions withOption(Key<T> key, T value) { public <T> CallOptions withOption(Key<T> key, T value) {
Preconditions.checkNotNull(key); Preconditions.checkNotNull(key, "key");
Preconditions.checkNotNull(value); Preconditions.checkNotNull(value, "value");
CallOptions newOptions = new CallOptions(this); CallOptions newOptions = new CallOptions(this);
int existingIdx = -1; int existingIdx = -1;
@ -335,7 +335,7 @@ public final class CallOptions {
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/1869") @ExperimentalApi("https://github.com/grpc/grpc-java/issues/1869")
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public <T> T getOption(Key<T> key) { public <T> T getOption(Key<T> key) {
Preconditions.checkNotNull(key); Preconditions.checkNotNull(key, "key");
for (int i = 0; i < customOptions.length; i++) { for (int i = 0; i < customOptions.length; i++) {
if (key.equals(customOptions[i][0])) { if (key.equals(customOptions[i][0])) {
return (T) customOptions[i][1]; return (T) customOptions[i][1];

View File

@ -98,7 +98,7 @@ public class ClientInterceptors {
* @return a new channel instance with the interceptors applied. * @return a new channel instance with the interceptors applied.
*/ */
public static Channel intercept(Channel channel, List<? extends ClientInterceptor> interceptors) { public static Channel intercept(Channel channel, List<? extends ClientInterceptor> interceptors) {
Preconditions.checkNotNull(channel); Preconditions.checkNotNull(channel, "channel");
for (ClientInterceptor interceptor : interceptors) { for (ClientInterceptor interceptor : interceptors) {
channel = new InterceptorChannel(channel, interceptor); channel = new InterceptorChannel(channel, interceptor);
} }

View File

@ -349,7 +349,7 @@ public class Context {
* will still be bound. * will still be bound.
*/ */
public void detach(Context toAttach) { public void detach(Context toAttach) {
Preconditions.checkNotNull(toAttach); Preconditions.checkNotNull(toAttach, "toAttach");
if (toAttach.attach() != this) { if (toAttach.attach() != this) {
// Log a severe message instead of throwing an exception as the context to attach is assumed // Log a severe message instead of throwing an exception as the context to attach is assumed
// to be the correct one and the unbalanced state represents a coding mistake in a lower // to be the correct one and the unbalanced state represents a coding mistake in a lower
@ -406,8 +406,8 @@ public class Context {
*/ */
public void addListener(final CancellationListener cancellationListener, public void addListener(final CancellationListener cancellationListener,
final Executor executor) { final Executor executor) {
Preconditions.checkNotNull(cancellationListener); Preconditions.checkNotNull(cancellationListener, "cancellationListener");
Preconditions.checkNotNull(executor); Preconditions.checkNotNull(executor, "executor");
if (canBeCancelled) { if (canBeCancelled) {
ExecutableListener executableListener = ExecutableListener executableListener =
new ExecutableListener(executor, cancellationListener); new ExecutableListener(executor, cancellationListener);
@ -778,7 +778,7 @@ public class Context {
} }
Key(String name, T defaultValue) { Key(String name, T defaultValue) {
this.name = Preconditions.checkNotNull(name); this.name = Preconditions.checkNotNull(name, "name");
this.defaultValue = defaultValue; this.defaultValue = defaultValue;
} }

View File

@ -60,7 +60,7 @@ public final class Deadline implements Comparable<Deadline> {
@VisibleForTesting @VisibleForTesting
static Deadline after(long duration, TimeUnit units, Ticker ticker) { static Deadline after(long duration, TimeUnit units, Ticker ticker) {
Preconditions.checkNotNull(units); Preconditions.checkNotNull(units, "units");
return new Deadline(ticker, units.toNanos(duration), true); return new Deadline(ticker, units.toNanos(duration), true);
} }

View File

@ -160,7 +160,7 @@ public final class DecompressorRegistry {
final boolean advertised; final boolean advertised;
DecompressorInfo(Decompressor decompressor, boolean advertised) { DecompressorInfo(Decompressor decompressor, boolean advertised) {
this.decompressor = checkNotNull(decompressor); this.decompressor = checkNotNull(decompressor, "decompressor");
this.advertised = advertised; this.advertised = advertised;
} }
} }

View File

@ -320,7 +320,7 @@ public final class Metadata {
* Perform a simple merge of two sets of metadata. * Perform a simple merge of two sets of metadata.
*/ */
public void merge(Metadata other) { public void merge(Metadata other) {
Preconditions.checkNotNull(other); Preconditions.checkNotNull(other, "other");
for (Map.Entry<String, List<MetadataEntry>> keyEntry : other.store.entrySet()) { for (Map.Entry<String, List<MetadataEntry>> keyEntry : other.store.entrySet()) {
for (int i = 0; i < keyEntry.getValue().size(); i++) { for (int i = 0; i < keyEntry.getValue().size(); i++) {
// Must copy the MetadataEntries since they are mutated. If the two Metadata objects are // Must copy the MetadataEntries since they are mutated. If the two Metadata objects are
@ -334,7 +334,7 @@ public final class Metadata {
* Merge values for the given set of keys into this set of metadata. * Merge values for the given set of keys into this set of metadata.
*/ */
public void merge(Metadata other, Set<Key<?>> keys) { public void merge(Metadata other, Set<Key<?>> keys) {
Preconditions.checkNotNull(other); Preconditions.checkNotNull(other, "other");
for (Key<?> key : keys) { for (Key<?> key : keys) {
List<MetadataEntry> values = other.store.get(key.name()); List<MetadataEntry> values = other.store.get(key.name());
if (values == null) { if (values == null) {
@ -480,7 +480,7 @@ public final class Metadata {
} }
private static String validateName(String n) { private static String validateName(String n) {
checkNotNull(n); checkNotNull(n, "name");
checkArgument(n.length() != 0, "token must have at least 1 tchar"); checkArgument(n.length() != 0, "token must have at least 1 tchar");
for (int i = 0; i < n.length(); i++) { for (int i = 0; i < n.length(); i++) {
char tChar = n.charAt(i); char tChar = n.charAt(i);
@ -496,7 +496,7 @@ public final class Metadata {
} }
private Key(String name) { private Key(String name) {
this.originalName = checkNotNull(name); this.originalName = checkNotNull(name, "name");
// Intern the result for faster string identity checking. // Intern the result for faster string identity checking.
this.name = validateName(this.originalName.toLowerCase(Locale.ROOT)).intern(); this.name = validateName(this.originalName.toLowerCase(Locale.ROOT)).intern();
this.nameBytes = this.name.getBytes(US_ASCII); this.nameBytes = this.name.getBytes(US_ASCII);
@ -604,7 +604,7 @@ public final class Metadata {
!name.endsWith(BINARY_HEADER_SUFFIX), !name.endsWith(BINARY_HEADER_SUFFIX),
"ASCII header is named %s. It must not end with %s", "ASCII header is named %s. It must not end with %s",
name, BINARY_HEADER_SUFFIX); name, BINARY_HEADER_SUFFIX);
this.marshaller = Preconditions.checkNotNull(marshaller); this.marshaller = Preconditions.checkNotNull(marshaller, "marshaller");
} }
@Override @Override
@ -630,8 +630,8 @@ public final class Metadata {
* Constructor used when application layer adds a parsed value. * Constructor used when application layer adds a parsed value.
*/ */
private MetadataEntry(Key<?> key, Object parsed) { private MetadataEntry(Key<?> key, Object parsed) {
this.parsed = Preconditions.checkNotNull(parsed); this.parsed = Preconditions.checkNotNull(parsed, "parsed");
this.key = Preconditions.checkNotNull(key); this.key = Preconditions.checkNotNull(key, "key");
this.isBinary = key instanceof BinaryKey; this.isBinary = key instanceof BinaryKey;
} }
@ -639,7 +639,7 @@ public final class Metadata {
* Constructor used when reading a value from the transport. * Constructor used when reading a value from the transport.
*/ */
private MetadataEntry(boolean isBinary, byte[] serialized) { private MetadataEntry(boolean isBinary, byte[] serialized) {
Preconditions.checkNotNull(serialized); Preconditions.checkNotNull(serialized, "serialized");
this.serializedBinary = serialized; this.serializedBinary = serialized;
this.isBinary = isBinary; this.isBinary = isBinary;
} }

View File

@ -105,7 +105,7 @@ public class ServerInterceptors {
public static ServerServiceDefinition intercept(BindableService bindableService, public static ServerServiceDefinition intercept(BindableService bindableService,
ServerInterceptor... interceptors) { ServerInterceptor... interceptors) {
Preconditions.checkNotNull(bindableService); Preconditions.checkNotNull(bindableService, "bindableService");
return intercept(bindableService.bindService(), Arrays.asList(interceptors)); return intercept(bindableService.bindService(), Arrays.asList(interceptors));
} }
@ -120,7 +120,7 @@ public class ServerInterceptors {
*/ */
public static ServerServiceDefinition intercept(ServerServiceDefinition serviceDef, public static ServerServiceDefinition intercept(ServerServiceDefinition serviceDef,
List<? extends ServerInterceptor> interceptors) { List<? extends ServerInterceptor> interceptors) {
Preconditions.checkNotNull(serviceDef); Preconditions.checkNotNull(serviceDef, "serviceDef");
if (interceptors.isEmpty()) { if (interceptors.isEmpty()) {
return serviceDef; return serviceDef;
} }
@ -134,7 +134,7 @@ public class ServerInterceptors {
public static ServerServiceDefinition intercept(BindableService bindableService, public static ServerServiceDefinition intercept(BindableService bindableService,
List<? extends ServerInterceptor> interceptors) { List<? extends ServerInterceptor> interceptors) {
Preconditions.checkNotNull(bindableService); Preconditions.checkNotNull(bindableService, "bindableService");
return intercept(bindableService.bindService(), interceptors); return intercept(bindableService.bindService(), interceptors);
} }

View File

@ -59,7 +59,7 @@ public final class ServerServiceDefinition {
private ServerServiceDefinition( private ServerServiceDefinition(
ServiceDescriptor serviceDescriptor, Map<String, ServerMethodDefinition<?, ?>> methods) { ServiceDescriptor serviceDescriptor, Map<String, ServerMethodDefinition<?, ?>> methods) {
this.serviceDescriptor = checkNotNull(serviceDescriptor); this.serviceDescriptor = checkNotNull(serviceDescriptor, "serviceDescriptor");
this.methods = ImmutableMap.copyOf(methods); this.methods = ImmutableMap.copyOf(methods);
} }

View File

@ -51,7 +51,7 @@ public final class ServiceDescriptor {
} }
public ServiceDescriptor(String name, Collection<MethodDescriptor<?, ?>> methods) { public ServiceDescriptor(String name, Collection<MethodDescriptor<?, ?>> methods) {
this.name = Preconditions.checkNotNull(name); this.name = Preconditions.checkNotNull(name, "name");
this.methods = Collections.unmodifiableList(new ArrayList<MethodDescriptor<?, ?>>(methods)); this.methods = Collections.unmodifiableList(new ArrayList<MethodDescriptor<?, ?>>(methods));
} }

View File

@ -406,7 +406,7 @@ public final class Status {
* @return non-{@code null} status * @return non-{@code null} status
*/ */
public static Status fromThrowable(Throwable t) { public static Status fromThrowable(Throwable t) {
Throwable cause = checkNotNull(t); Throwable cause = checkNotNull(t, "t");
while (cause != null) { while (cause != null) {
if (cause instanceof StatusException) { if (cause instanceof StatusException) {
return ((StatusException) cause).getStatus(); return ((StatusException) cause).getStatus();
@ -426,7 +426,7 @@ public final class Status {
*/ */
@ExperimentalApi @ExperimentalApi
public static Metadata trailersFromThrowable(Throwable t) { public static Metadata trailersFromThrowable(Throwable t) {
Throwable cause = checkNotNull(t); Throwable cause = checkNotNull(t, "t");
while (cause != null) { while (cause != null) {
if (cause instanceof StatusException) { if (cause instanceof StatusException) {
return ((StatusException) cause).getTrailers(); return ((StatusException) cause).getTrailers();
@ -455,7 +455,7 @@ public final class Status {
} }
private Status(Code code, @Nullable String description, @Nullable Throwable cause) { private Status(Code code, @Nullable String description, @Nullable Throwable cause) {
this.code = checkNotNull(code); this.code = checkNotNull(code, "code");
this.description = description; this.description = description;
this.cause = cause; this.cause = cause;
} }

View File

@ -64,7 +64,7 @@ public class InProcessChannelBuilder extends
private InProcessChannelBuilder(String name) { private InProcessChannelBuilder(String name) {
super(new InProcessSocketAddress(name), "localhost"); super(new InProcessSocketAddress(name), "localhost");
this.name = Preconditions.checkNotNull(name); this.name = Preconditions.checkNotNull(name, "name");
} }
/** /**

View File

@ -233,8 +233,8 @@ class InProcessTransport implements ServerTransport, ConnectionClientTransport {
private MethodDescriptor<?, ?> method; private MethodDescriptor<?, ?> method;
private InProcessStream(MethodDescriptor<?, ?> method, Metadata headers) { private InProcessStream(MethodDescriptor<?, ?> method, Metadata headers) {
this.method = checkNotNull(method); this.method = checkNotNull(method, "method");
this.headers = checkNotNull(headers); this.headers = checkNotNull(headers, "headers");
} }

View File

@ -112,7 +112,7 @@ public abstract class AbstractManagedChannelImplBuilder
private long idleTimeoutMillis = ManagedChannelImpl.IDLE_TIMEOUT_MILLIS_DISABLE; private long idleTimeoutMillis = ManagedChannelImpl.IDLE_TIMEOUT_MILLIS_DISABLE;
protected AbstractManagedChannelImplBuilder(String target) { protected AbstractManagedChannelImplBuilder(String target) {
this.target = Preconditions.checkNotNull(target); this.target = Preconditions.checkNotNull(target, "target");
this.directServerAddress = null; this.directServerAddress = null;
} }

View File

@ -177,7 +177,7 @@ public abstract class AbstractServerStream extends AbstractStream2
* thread. * thread.
*/ */
public final void setListener(ServerStreamListener listener) { public final void setListener(ServerStreamListener listener) {
this.listener = Preconditions.checkNotNull(listener); this.listener = Preconditions.checkNotNull(listener, "listener");
// Now that the stream has actually been initialized, call the listener's onReady callback if // Now that the stream has actually been initialized, call the listener's onReady callback if
// appropriate. // appropriate.

View File

@ -166,7 +166,7 @@ public abstract class AbstractStream<IdT> implements Stream {
@Override @Override
public void writeMessage(InputStream message) { public void writeMessage(InputStream message) {
checkNotNull(message); checkNotNull(message, "message");
outboundPhase(Phase.MESSAGE); outboundPhase(Phase.MESSAGE);
if (!framer.isClosed()) { if (!framer.isClosed()) {
framer.writePayload(message); framer.writePayload(message);

View File

@ -65,7 +65,7 @@ public abstract class AbstractStream2 implements Stream {
@Override @Override
public final void writeMessage(InputStream message) { public final void writeMessage(InputStream message) {
checkNotNull(message); checkNotNull(message, "message");
if (!framer().isClosed()) { if (!framer().isClosed()) {
framer().writePayload(message); framer().writePayload(message);
} }

View File

@ -82,7 +82,7 @@ public abstract class Http2ClientStream extends AbstractClientStream<Integer> {
* @param headers the received headers * @param headers the received headers
*/ */
protected void transportHeadersReceived(Metadata headers) { protected void transportHeadersReceived(Metadata headers) {
Preconditions.checkNotNull(headers); Preconditions.checkNotNull(headers, "headers");
if (transportError != null) { if (transportError != null) {
// Already received a transport error so just augment it. // Already received a transport error so just augment it.
transportError = transportError.augmentDescription(headers.toString()); transportError = transportError.augmentDescription(headers.toString());
@ -150,7 +150,7 @@ public abstract class Http2ClientStream extends AbstractClientStream<Integer> {
* @param trailers the received terminal trailer metadata * @param trailers the received terminal trailer metadata
*/ */
protected void transportTrailersReceived(Metadata trailers) { protected void transportTrailersReceived(Metadata trailers) {
Preconditions.checkNotNull(trailers); Preconditions.checkNotNull(trailers, "trailers");
if (transportError != null) { if (transportError != null) {
// Already received a transport error so just augment it. // Already received a transport error so just augment it.
transportError = transportError.augmentDescription(trailers.toString()); transportError = transportError.augmentDescription(trailers.toString());

View File

@ -49,7 +49,7 @@ public final class LogExceptionRunnable implements Runnable {
private final Runnable task; private final Runnable task;
public LogExceptionRunnable(Runnable task) { public LogExceptionRunnable(Runnable task) {
this.task = checkNotNull(task); this.task = checkNotNull(task, "task");
} }
@Override @Override

View File

@ -123,7 +123,7 @@ public final class ServerImpl extends io.grpc.Server {
this.transportServer = Preconditions.checkNotNull(transportServer, "transportServer"); this.transportServer = Preconditions.checkNotNull(transportServer, "transportServer");
// Fork from the passed in context so that it does not propagate cancellation, it only // Fork from the passed in context so that it does not propagate cancellation, it only
// inherits values. // inherits values.
this.rootContext = Preconditions.checkNotNull(rootContext).fork(); this.rootContext = Preconditions.checkNotNull(rootContext, "rootContext").fork();
this.decompressorRegistry = decompressorRegistry; this.decompressorRegistry = decompressorRegistry;
this.compressorRegistry = compressorRegistry; this.compressorRegistry = compressorRegistry;
} }

View File

@ -364,10 +364,11 @@ public class StressTestClient {
Worker(ManagedChannel channel, List<TestCaseWeightPair> testCaseWeightPairs, Worker(ManagedChannel channel, List<TestCaseWeightPair> testCaseWeightPairs,
int durationSec, String gaugeName) { int durationSec, String gaugeName) {
Preconditions.checkArgument(durationSec >= -1, "durationSec must be gte -1."); Preconditions.checkArgument(durationSec >= -1, "durationSec must be gte -1.");
this.channel = Preconditions.checkNotNull(channel); this.channel = Preconditions.checkNotNull(channel, "channel");
this.testCaseWeightPairs = Preconditions.checkNotNull(testCaseWeightPairs); this.testCaseWeightPairs =
Preconditions.checkNotNull(testCaseWeightPairs, "testCaseWeightPairs");
this.durationSec = durationSec == -1 ? null : durationSec; this.durationSec = durationSec == -1 ? null : durationSec;
this.gaugeName = Preconditions.checkNotNull(gaugeName); this.gaugeName = Preconditions.checkNotNull(gaugeName, "gaugeName");
} }
@Override @Override
@ -493,7 +494,7 @@ public class StressTestClient {
final Iterator<TestCases> testCases; final Iterator<TestCases> testCases;
WeightedTestCaseSelector(List<TestCaseWeightPair> testCaseWeightPairs) { WeightedTestCaseSelector(List<TestCaseWeightPair> testCaseWeightPairs) {
Preconditions.checkNotNull(testCaseWeightPairs); Preconditions.checkNotNull(testCaseWeightPairs, "testCaseWeightPairs");
Preconditions.checkArgument(testCaseWeightPairs.size() > 0); Preconditions.checkArgument(testCaseWeightPairs.size() > 0);
List<TestCases> testCases = new ArrayList<TestCases>(); List<TestCases> testCases = new ArrayList<TestCases>();
@ -549,7 +550,7 @@ public class StressTestClient {
TestCaseWeightPair(TestCases testCase, int weight) { TestCaseWeightPair(TestCases testCase, int weight) {
Preconditions.checkArgument(weight >= 0, "weight must be positive."); Preconditions.checkArgument(weight >= 0, "weight must be positive.");
this.testCase = Preconditions.checkNotNull(testCase); this.testCase = Preconditions.checkNotNull(testCase, "testCase");
this.weight = weight; this.weight = weight;
} }

View File

@ -71,7 +71,7 @@ public enum TestCases {
* matching is done case insensitive. * matching is done case insensitive.
*/ */
public static TestCases fromString(String s) { public static TestCases fromString(String s) {
Preconditions.checkNotNull(s); Preconditions.checkNotNull(s, "s");
return TestCases.valueOf(s.toUpperCase()); return TestCases.valueOf(s.toUpperCase());
} }
} }

View File

@ -44,7 +44,7 @@ class CancelClientStreamCommand extends WriteQueue.AbstractQueuedCommand {
CancelClientStreamCommand(NettyClientStream stream, Status reason) { CancelClientStreamCommand(NettyClientStream stream, Status reason) {
this.stream = Preconditions.checkNotNull(stream, "stream"); this.stream = Preconditions.checkNotNull(stream, "stream");
Preconditions.checkNotNull(reason); Preconditions.checkNotNull(reason, "reason");
Preconditions.checkArgument(!reason.isOk(), "Should not cancel with OK status"); Preconditions.checkArgument(!reason.isOk(), "Should not cancel with OK status");
this.reason = reason; this.reason = reason;
} }

View File

@ -45,8 +45,8 @@ class CancelServerStreamCommand extends WriteQueue.AbstractQueuedCommand {
private final Status reason; private final Status reason;
CancelServerStreamCommand(NettyServerStream.TransportState stream, Status reason) { CancelServerStreamCommand(NettyServerStream.TransportState stream, Status reason) {
this.stream = Preconditions.checkNotNull(stream); this.stream = Preconditions.checkNotNull(stream, "stream");
this.reason = Preconditions.checkNotNull(reason); this.reason = Preconditions.checkNotNull(reason, "reason");
} }
NettyServerStream.TransportState stream() { NettyServerStream.TransportState stream() {

View File

@ -124,7 +124,7 @@ public class NettyChannelBuilder extends AbstractManagedChannelImplBuilder<Netty
* Specify the channel type to use, by default we use {@link NioSocketChannel}. * Specify the channel type to use, by default we use {@link NioSocketChannel}.
*/ */
public final NettyChannelBuilder channelType(Class<? extends Channel> channelType) { public final NettyChannelBuilder channelType(Class<? extends Channel> channelType) {
this.channelType = Preconditions.checkNotNull(channelType); this.channelType = Preconditions.checkNotNull(channelType, "channelType");
return this; return this;
} }

View File

@ -104,7 +104,7 @@ public final class NettyServerBuilder extends AbstractServerImplBuilder<NettySer
* Specify the channel type to use, by default we use {@link NioServerSocketChannel}. * Specify the channel type to use, by default we use {@link NioServerSocketChannel}.
*/ */
public NettyServerBuilder channelType(Class<? extends ServerChannel> channelType) { public NettyServerBuilder channelType(Class<? extends ServerChannel> channelType) {
this.channelType = Preconditions.checkNotNull(channelType); this.channelType = Preconditions.checkNotNull(channelType, "channelType");
return this; return this;
} }

View File

@ -223,8 +223,8 @@ public final class ProtocolNegotiators {
private final int port; private final int port;
TlsNegotiator(SslContext sslContext, String host, int port) { TlsNegotiator(SslContext sslContext, String host, int port) {
this.sslContext = checkNotNull(sslContext); this.sslContext = checkNotNull(sslContext, "sslContext");
this.host = checkNotNull(host); this.host = checkNotNull(host, "host");
this.port = port; this.port = port;
} }

View File

@ -44,8 +44,8 @@ class SendResponseHeadersCommand extends WriteQueue.AbstractQueuedCommand {
private final boolean endOfStream; private final boolean endOfStream;
SendResponseHeadersCommand(StreamIdHolder stream, Http2Headers headers, boolean endOfStream) { SendResponseHeadersCommand(StreamIdHolder stream, Http2Headers headers, boolean endOfStream) {
this.stream = Preconditions.checkNotNull(stream); this.stream = Preconditions.checkNotNull(stream, "stream");
this.headers = Preconditions.checkNotNull(headers); this.headers = Preconditions.checkNotNull(headers, "headers");
this.endOfStream = endOfStream; this.endOfStream = endOfStream;
} }

View File

@ -70,8 +70,8 @@ class AsyncFrameWriter implements FrameWriter {
void becomeConnected(FrameWriter frameWriter, Socket socket) { void becomeConnected(FrameWriter frameWriter, Socket socket) {
Preconditions.checkState(this.frameWriter == null, Preconditions.checkState(this.frameWriter == null,
"AsyncFrameWriter's setFrameWriter() should only be called once."); "AsyncFrameWriter's setFrameWriter() should only be called once.");
this.frameWriter = Preconditions.checkNotNull(frameWriter); this.frameWriter = Preconditions.checkNotNull(frameWriter, "frameWriter");
this.socket = Preconditions.checkNotNull(socket); this.socket = Preconditions.checkNotNull(socket, "socket");
} }
@Override @Override

View File

@ -154,7 +154,7 @@ public class OkHttpChannelBuilder extends
* <p>Default: <code>TLS</code> * <p>Default: <code>TLS</code>
*/ */
public final OkHttpChannelBuilder negotiationType(NegotiationType type) { public final OkHttpChannelBuilder negotiationType(NegotiationType type) {
negotiationType = Preconditions.checkNotNull(type); negotiationType = Preconditions.checkNotNull(type, "type");
return this; return this;
} }

View File

@ -211,16 +211,16 @@ class OkHttpClientTransport implements ConnectionClientTransport {
this.maxMessageSize = maxMessageSize; this.maxMessageSize = maxMessageSize;
defaultAuthority = "notarealauthority:80"; defaultAuthority = "notarealauthority:80";
this.userAgent = GrpcUtil.getGrpcUserAgent("okhttp", userAgent); this.userAgent = GrpcUtil.getGrpcUserAgent("okhttp", userAgent);
this.executor = Preconditions.checkNotNull(executor); this.executor = Preconditions.checkNotNull(executor, "executor");
serializingExecutor = new SerializingExecutor(executor); serializingExecutor = new SerializingExecutor(executor);
this.testFrameReader = Preconditions.checkNotNull(frameReader); this.testFrameReader = Preconditions.checkNotNull(frameReader, "frameReader");
this.testFrameWriter = Preconditions.checkNotNull(testFrameWriter); this.testFrameWriter = Preconditions.checkNotNull(testFrameWriter, "testFrameWriter");
this.socket = Preconditions.checkNotNull(socket); this.socket = Preconditions.checkNotNull(socket, "socket");
this.nextStreamId = nextStreamId; this.nextStreamId = nextStreamId;
this.ticker = ticker; this.ticker = ticker;
this.connectionSpec = null; this.connectionSpec = null;
this.connectingCallback = connectingCallback; this.connectingCallback = connectingCallback;
this.connectedFuture = Preconditions.checkNotNull(connectedFuture); this.connectedFuture = Preconditions.checkNotNull(connectedFuture, "connectedFuture");
} }
/** /**

View File

@ -61,7 +61,7 @@ class OkHttpProtocolNegotiator {
@VisibleForTesting @VisibleForTesting
OkHttpProtocolNegotiator(Platform platform) { OkHttpProtocolNegotiator(Platform platform) {
this.platform = checkNotNull(platform); this.platform = checkNotNull(platform, "platform");
} }
public static OkHttpProtocolNegotiator get() { public static OkHttpProtocolNegotiator get() {

View File

@ -65,9 +65,9 @@ final class OkHttpTlsUpgrader {
*/ */
public static SSLSocket upgrade(SSLSocketFactory sslSocketFactory, public static SSLSocket upgrade(SSLSocketFactory sslSocketFactory,
Socket socket, String host, int port, ConnectionSpec spec) throws IOException { Socket socket, String host, int port, ConnectionSpec spec) throws IOException {
Preconditions.checkNotNull(sslSocketFactory); Preconditions.checkNotNull(sslSocketFactory, "sslSocketFactory");
Preconditions.checkNotNull(socket); Preconditions.checkNotNull(socket, "socket");
Preconditions.checkNotNull(spec); Preconditions.checkNotNull(spec, "spec");
SSLSocket sslSocket = (SSLSocket) sslSocketFactory.createSocket( SSLSocket sslSocket = (SSLSocket) sslSocketFactory.createSocket(
socket, host, port, true /* auto close */); socket, host, port, true /* auto close */);
spec.apply(sslSocket, false); spec.apply(sslSocket, false);

View File

@ -73,8 +73,8 @@ public abstract class AbstractStub<S extends AbstractStub<S>> {
* @param callOptions the runtime call options to be applied to every call on this stub * @param callOptions the runtime call options to be applied to every call on this stub
*/ */
protected AbstractStub(Channel channel, CallOptions callOptions) { protected AbstractStub(Channel channel, CallOptions callOptions) {
this.channel = checkNotNull(channel); this.channel = checkNotNull(channel, "channel");
this.callOptions = checkNotNull(callOptions); this.callOptions = checkNotNull(callOptions, "callOptions");
} }
/** /**
@ -155,7 +155,7 @@ public abstract class AbstractStub<S extends AbstractStub<S>> {
public final S withChannel(Channel newChannel) { public final S withChannel(Channel newChannel) {
return build(newChannel, callOptions); return build(newChannel, callOptions);
} }
/** /**
* Sets a custom option to be passed to client interceptors on the channel * Sets a custom option to be passed to client interceptors on the channel
* {@link io.grpc.ClientInterceptor} via the CallOptions parameter. * {@link io.grpc.ClientInterceptor} via the CallOptions parameter.

View File

@ -219,7 +219,7 @@ public class ClientCalls {
* exception will be generated from an {@link Status#UNKNOWN} status. * exception will be generated from an {@link Status#UNKNOWN} status.
*/ */
private static StatusRuntimeException toStatusRuntimeException(Throwable t) { private static StatusRuntimeException toStatusRuntimeException(Throwable t) {
Throwable cause = checkNotNull(t); Throwable cause = checkNotNull(t, "t");
while (cause != null) { while (cause != null) {
// If we have an embedded status, use it and replace the cause // If we have an embedded status, use it and replace the cause
if (cause instanceof StatusException) { if (cause instanceof StatusException) {

View File

@ -372,8 +372,8 @@ public class ServerCalls {
*/ */
public static void asyncUnimplementedUnaryCall(MethodDescriptor<?, ?> methodDescriptor, public static void asyncUnimplementedUnaryCall(MethodDescriptor<?, ?> methodDescriptor,
StreamObserver<?> responseObserver) { StreamObserver<?> responseObserver) {
checkNotNull(methodDescriptor); checkNotNull(methodDescriptor, "methodDescriptor");
checkNotNull(responseObserver); checkNotNull(responseObserver, "responseObserver");
responseObserver.onError(Status.UNIMPLEMENTED responseObserver.onError(Status.UNIMPLEMENTED
.withDescription(String.format("Method %s is unimplemented", .withDescription(String.format("Method %s is unimplemented",
methodDescriptor.getFullMethodName())) methodDescriptor.getFullMethodName()))

View File

@ -56,8 +56,8 @@ public class StreamObservers {
*/ */
public static <V> void copyWithFlowControl(final Iterator<V> source, public static <V> void copyWithFlowControl(final Iterator<V> source,
final CallStreamObserver<V> target) { final CallStreamObserver<V> target) {
Preconditions.checkNotNull(source); Preconditions.checkNotNull(source, "source");
Preconditions.checkNotNull(target); Preconditions.checkNotNull(target, "target");
target.setOnReadyHandler(new Runnable() { target.setOnReadyHandler(new Runnable() {
@Override @Override
public void run() { public void run() {
@ -84,7 +84,7 @@ public class StreamObservers {
*/ */
public static <V> void copyWithFlowControl(final Iterable<V> source, public static <V> void copyWithFlowControl(final Iterable<V> source,
CallStreamObserver<V> target) { CallStreamObserver<V> target) {
Preconditions.checkNotNull(source); Preconditions.checkNotNull(source, "source");
copyWithFlowControl(source.iterator(), target); copyWithFlowControl(source.iterator(), target);
} }
} }