Skip to content

Commit

Permalink
Upgrade errorprone to 2.18
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminp committed Feb 10, 2023
1 parent f6a0028 commit 8697f9f
Show file tree
Hide file tree
Showing 37 changed files with 117 additions and 164 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public void testVectorEncrypt() throws GeneralSecurityException {
ByteBuffer.wrap(testVector.plaintext),
ByteBuffer.wrap(testVector.aad),
testVector.nonce);
String msg = "Failure for test vector " + i;
String msg = "Failure for test vector " + i + " " + testVector.comment;
assertWithMessage(msg)
.that(ciphertextBuffer.remaining())
.isEqualTo(bufferSize - testVector.ciphertext.length);
Expand All @@ -142,7 +142,7 @@ public void testVectorDecrypt() throws GeneralSecurityException {
ByteBuffer.wrap(testVector.ciphertext),
ByteBuffer.wrap(testVector.aad),
testVector.nonce);
String msg = "Failure for test vector " + i;
String msg = "Failure for test vector " + i + " " + testVector.comment;
assertWithMessage(msg)
.that(plaintextBuffer.remaining())
.isEqualTo(bufferSize - testVector.plaintext.length);
Expand Down
1 change: 1 addition & 0 deletions api/src/main/java/io/grpc/Attributes.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ public Builder toBuilder() {
* @param <T> type of the value in the key-value pair
*/
@Immutable
@SuppressWarnings("UnusedTypeParameter")
public static final class Key<T> {
private final String debugString;

Expand Down
2 changes: 1 addition & 1 deletion api/src/main/java/io/grpc/LoadBalancer.java
Original file line number Diff line number Diff line change
Expand Up @@ -772,7 +772,7 @@ public static final class Builder {
Builder() {
}

private <T> Builder copyCustomOptions(Object[][] options) {
private Builder copyCustomOptions(Object[][] options) {
customOptions = new Object[options.length][2];
System.arraycopy(options, 0, customOptions, 0, options.length);
return this;
Expand Down
12 changes: 0 additions & 12 deletions api/src/test/java/io/grpc/CallOptionsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import io.grpc.ClientStreamTracer.StreamInfo;
import io.grpc.internal.SerializingExecutor;
import java.util.concurrent.Executor;
import java.util.concurrent.TimeUnit;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
Expand Down Expand Up @@ -259,17 +258,6 @@ private static class FakeTicker extends Deadline.Ticker {
public long nanoTime() {
return time;
}

public void reset(long time) {
this.time = time;
}

public void increment(long period, TimeUnit unit) {
if (period < 0) {
throw new IllegalArgumentException();
}
this.time += unit.toNanos(period);
}
}

private static class FakeTracerFactory extends ClientStreamTracer.Factory {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ public SimpleResponse unaryCallsByteThroughput() {
return stub.unaryCall(BYTE_THROUGHPUT_REQUEST);
}

@SuppressWarnings("StaticAssignmentOfThrowable")
private static final Throwable OK_THROWABLE = new RuntimeException("OK");

@State(Scope.Thread)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,9 @@ Stats.ClientStats getStats() {
latenciesBuilder.addBucket(0);
base = base * resolution;
}
latenciesBuilder.setMaxSeen(intervalHistogram.getMaxValue());
latenciesBuilder.setMinSeen(intervalHistogram.getMinNonZeroValue());
latenciesBuilder.setCount(intervalHistogram.getTotalCount());
latenciesBuilder.setMaxSeen((double) intervalHistogram.getMaxValue());
latenciesBuilder.setMinSeen((double) intervalHistogram.getMinNonZeroValue());
latenciesBuilder.setCount((double) intervalHistogram.getTotalCount());
latenciesBuilder.setSum(intervalHistogram.getMean()
* intervalHistogram.getTotalCount());
// TODO: No support for sum of squares
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ public void onCompleted() {

private void waitForRpcsToComplete(int duration) {
long now = System.nanoTime();
long end = now + duration * 1000 * 1000 * 1000;
long end = now + duration * 1000L * 1000L * 1000L;
while (histogram.getTotalCount() < numRpcs && end - now > 0) {
now = System.nanoTime();
}
Expand Down
80 changes: 46 additions & 34 deletions census/src/main/java/io/grpc/census/CensusStatsModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ public void outboundWireSize(long bytes) {
outboundWireSize += bytes;
}
module.recordRealTimeMetric(
startCtx, RpcMeasureConstants.GRPC_CLIENT_SENT_BYTES_PER_METHOD, bytes);
startCtx, RpcMeasureConstants.GRPC_CLIENT_SENT_BYTES_PER_METHOD, (double) bytes);
}

@Override
Expand All @@ -288,7 +288,7 @@ public void inboundWireSize(long bytes) {
inboundWireSize += bytes;
}
module.recordRealTimeMetric(
startCtx, RpcMeasureConstants.GRPC_CLIENT_RECEIVED_BYTES_PER_METHOD, bytes);
startCtx, RpcMeasureConstants.GRPC_CLIENT_RECEIVED_BYTES_PER_METHOD, (double) bytes);
}

@Override
Expand Down Expand Up @@ -365,21 +365,27 @@ public void streamClosed(Status status) {
}

void recordFinishedAttempt() {
MeasureMap measureMap = module.statsRecorder.newMeasureMap()
// TODO(songya): remove the deprecated measure constants once they are completed removed.
.put(DeprecatedCensusConstants.RPC_CLIENT_FINISHED_COUNT, 1)
// The latency is double value
.put(RpcMeasureConstants.GRPC_CLIENT_ROUNDTRIP_LATENCY, roundtripNanos / NANOS_PER_MILLI)
.put(RpcMeasureConstants.GRPC_CLIENT_SENT_MESSAGES_PER_RPC, outboundMessageCount)
.put(RpcMeasureConstants.GRPC_CLIENT_RECEIVED_MESSAGES_PER_RPC, inboundMessageCount)
.put(RpcMeasureConstants.GRPC_CLIENT_SENT_BYTES_PER_RPC, outboundWireSize)
.put(RpcMeasureConstants.GRPC_CLIENT_RECEIVED_BYTES_PER_RPC, inboundWireSize)
.put(
DeprecatedCensusConstants.RPC_CLIENT_UNCOMPRESSED_REQUEST_BYTES,
outboundUncompressedSize)
.put(
DeprecatedCensusConstants.RPC_CLIENT_UNCOMPRESSED_RESPONSE_BYTES,
inboundUncompressedSize);
MeasureMap measureMap =
module
.statsRecorder
.newMeasureMap()
// TODO(songya): remove the deprecated measure constants once they are completed
// removed.
.put(DeprecatedCensusConstants.RPC_CLIENT_FINISHED_COUNT, 1)
// The latency is double value
.put(
RpcMeasureConstants.GRPC_CLIENT_ROUNDTRIP_LATENCY,
roundtripNanos / NANOS_PER_MILLI)
.put(RpcMeasureConstants.GRPC_CLIENT_SENT_MESSAGES_PER_RPC, outboundMessageCount)
.put(RpcMeasureConstants.GRPC_CLIENT_RECEIVED_MESSAGES_PER_RPC, inboundMessageCount)
.put(RpcMeasureConstants.GRPC_CLIENT_SENT_BYTES_PER_RPC, (double) outboundWireSize)
.put(RpcMeasureConstants.GRPC_CLIENT_RECEIVED_BYTES_PER_RPC, (double) inboundWireSize)
.put(
DeprecatedCensusConstants.RPC_CLIENT_UNCOMPRESSED_REQUEST_BYTES,
(double) outboundUncompressedSize)
.put(
DeprecatedCensusConstants.RPC_CLIENT_UNCOMPRESSED_RESPONSE_BYTES,
(double) inboundUncompressedSize);
if (statusCode != Code.OK) {
measureMap.put(DeprecatedCensusConstants.RPC_CLIENT_ERROR_COUNT, 1);
}
Expand Down Expand Up @@ -640,7 +646,7 @@ public void outboundWireSize(long bytes) {
outboundWireSize += bytes;
}
module.recordRealTimeMetric(
parentCtx, RpcMeasureConstants.GRPC_SERVER_SENT_BYTES_PER_METHOD, bytes);
parentCtx, RpcMeasureConstants.GRPC_SERVER_SENT_BYTES_PER_METHOD, (double) bytes);
}

@Override
Expand All @@ -652,7 +658,7 @@ public void inboundWireSize(long bytes) {
inboundWireSize += bytes;
}
module.recordRealTimeMetric(
parentCtx, RpcMeasureConstants.GRPC_SERVER_RECEIVED_BYTES_PER_METHOD, bytes);
parentCtx, RpcMeasureConstants.GRPC_SERVER_RECEIVED_BYTES_PER_METHOD, (double) bytes);
}

@Override
Expand Down Expand Up @@ -722,21 +728,27 @@ public void streamClosed(Status status) {
}
stopwatch.stop();
long elapsedTimeNanos = stopwatch.elapsed(TimeUnit.NANOSECONDS);
MeasureMap measureMap = module.statsRecorder.newMeasureMap()
// TODO(songya): remove the deprecated measure constants once they are completed removed.
.put(DeprecatedCensusConstants.RPC_SERVER_FINISHED_COUNT, 1)
// The latency is double value
.put(RpcMeasureConstants.GRPC_SERVER_SERVER_LATENCY, elapsedTimeNanos / NANOS_PER_MILLI)
.put(RpcMeasureConstants.GRPC_SERVER_SENT_MESSAGES_PER_RPC, outboundMessageCount)
.put(RpcMeasureConstants.GRPC_SERVER_RECEIVED_MESSAGES_PER_RPC, inboundMessageCount)
.put(RpcMeasureConstants.GRPC_SERVER_SENT_BYTES_PER_RPC, outboundWireSize)
.put(RpcMeasureConstants.GRPC_SERVER_RECEIVED_BYTES_PER_RPC, inboundWireSize)
.put(
DeprecatedCensusConstants.RPC_SERVER_UNCOMPRESSED_RESPONSE_BYTES,
outboundUncompressedSize)
.put(
DeprecatedCensusConstants.RPC_SERVER_UNCOMPRESSED_REQUEST_BYTES,
inboundUncompressedSize);
MeasureMap measureMap =
module
.statsRecorder
.newMeasureMap()
// TODO(songya): remove the deprecated measure constants once they are completed
// removed.
.put(DeprecatedCensusConstants.RPC_SERVER_FINISHED_COUNT, 1)
// The latency is double value
.put(
RpcMeasureConstants.GRPC_SERVER_SERVER_LATENCY,
elapsedTimeNanos / NANOS_PER_MILLI)
.put(RpcMeasureConstants.GRPC_SERVER_SENT_MESSAGES_PER_RPC, outboundMessageCount)
.put(RpcMeasureConstants.GRPC_SERVER_RECEIVED_MESSAGES_PER_RPC, inboundMessageCount)
.put(RpcMeasureConstants.GRPC_SERVER_SENT_BYTES_PER_RPC, (double) outboundWireSize)
.put(RpcMeasureConstants.GRPC_SERVER_RECEIVED_BYTES_PER_RPC, (double) inboundWireSize)
.put(
DeprecatedCensusConstants.RPC_SERVER_UNCOMPRESSED_RESPONSE_BYTES,
(double) outboundUncompressedSize)
.put(
DeprecatedCensusConstants.RPC_SERVER_UNCOMPRESSED_REQUEST_BYTES,
(double) inboundUncompressedSize);
if (!status.isOk()) {
measureMap.put(DeprecatedCensusConstants.RPC_SERVER_ERROR_COUNT, 1);
}
Expand Down
6 changes: 2 additions & 4 deletions core/src/main/java/io/grpc/internal/InternalSubchannel.java
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ private void startNewTransport() {
channelz.addClientSocket(transport);
pendingTransport = transport;
transports.add(transport);
Runnable runnable = transport.start(new TransportListener(transport, address));
Runnable runnable = transport.start(new TransportListener(transport));
if (runnable != null) {
syncContext.executeLater(runnable);
}
Expand Down Expand Up @@ -533,12 +533,10 @@ private static void checkListHasNoNulls(List<?> list, String msg) {
/** Listener for real transports. */
private class TransportListener implements ManagedClientTransport.Listener {
final ConnectionClientTransport transport;
final SocketAddress address;
boolean shutdownInitiated = false;

TransportListener(ConnectionClientTransport transport, SocketAddress address) {
TransportListener(ConnectionClientTransport transport) {
this.transport = transport;
this.address = address;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
final class JndiResourceResolverFactory implements DnsNameResolver.ResourceResolverFactory {

@Nullable
@SuppressWarnings("StaticAssignmentOfThrowable")
private static final Throwable JNDI_UNAVAILABILITY_CAUSE = initJndi();

// @UsedReflectively
Expand Down Expand Up @@ -194,8 +195,7 @@ static String unquote(String txtRecord) {

@VisibleForTesting
@IgnoreJRERequirement
// Hashtable is required. https://github.com/google/error-prone/issues/1766
@SuppressWarnings("JdkObsolete")
@SuppressWarnings({"JdkObsolete", "BanJNDI"})
// javax.naming.* is only loaded reflectively and is never loaded for Android
// The lint issue id is supposed to be "InvalidPackage" but it doesn't work, don't know why.
// Use "all" as the lint issue id to suppress all types of lint error.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ static final class ManagedChannelReference extends WeakReference<ManagedChannelO

private static final boolean ENABLE_ALLOCATION_TRACKING =
Boolean.parseBoolean(System.getProperty(ALLOCATION_SITE_PROPERTY_NAME, "true"));

@SuppressWarnings("StaticAssignmentOfThrowable")
private static final RuntimeException missingCallSite = missingCallSite();

private final ReferenceQueue<ManagedChannelOrphanWrapper> refqueue;
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/java/io/grpc/internal/StatsTraceContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,11 @@ public void clientInboundTrailers(Metadata trailers) {
}

/**
* See {@link ServerStreamTracer#filterContext}. For server-side only.
* See {@link ServerStreamTracer#filterContext}. For server-side only.
*
* <p>Called from {@link io.grpc.internal.ServerImpl}.
*/
@SuppressWarnings("UnusedTypeParameter")
public <ReqT, RespT> Context serverFilterContext(Context context) {
Context ctx = checkNotNull(context, "context");
for (StreamTracer tracer : tracers) {
Expand Down
8 changes: 4 additions & 4 deletions core/src/test/java/io/grpc/internal/KeepAliveManagerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ public void keepAlivePingDelayedByIncomingData() {
@Test
public void clientKeepAlivePinger_pingTimeout() {
ConnectionClientTransport transport = mock(ConnectionClientTransport.class);
keepAlivePinger = new ClientKeepAlivePinger(transport);
ClientKeepAlivePinger pinger = new ClientKeepAlivePinger(transport);

keepAlivePinger.onPingTimeout();
pinger.onPingTimeout();

ArgumentCaptor<Status> statusCaptor = ArgumentCaptor.forClass(Status.class);
verify(transport).shutdownNow(statusCaptor.capture());
Expand All @@ -120,8 +120,8 @@ public void clientKeepAlivePinger_pingTimeout() {
@Test
public void clientKeepAlivePinger_pingFailure() {
ConnectionClientTransport transport = mock(ConnectionClientTransport.class);
keepAlivePinger = new ClientKeepAlivePinger(transport);
keepAlivePinger.ping();
ClientKeepAlivePinger pinger = new ClientKeepAlivePinger(transport);
pinger.ping();
ArgumentCaptor<ClientTransport.PingCallback> pingCallbackCaptor =
ArgumentCaptor.forClass(ClientTransport.PingCallback.class);
verify(transport).ping(pingCallbackCaptor.capture(), isA(Executor.class));
Expand Down
7 changes: 6 additions & 1 deletion core/src/test/java/io/grpc/internal/RetriableStreamTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,17 @@ private final class RecordedRetriableStream extends RetriableStream<String> {
}

@Override
@SuppressWarnings("DirectInvocationOnMock")
void postCommit() {
retriableStreamRecorder.postCommit();
}

@Override
@SuppressWarnings("DirectInvocationOnMock")
ClientStream newSubstream(
Metadata metadata, ClientStreamTracer.Factory tracerFactory, int previousAttempts,
Metadata metadata,
ClientStreamTracer.Factory tracerFactory,
int previousAttempts,
boolean isTransparentRetry) {
bufferSizeTracer =
tracerFactory.newClientStreamTracer(STREAM_INFO, metadata);
Expand All @@ -178,6 +182,7 @@ ClientStream newSubstream(
}

@Override
@SuppressWarnings("DirectInvocationOnMock")
Status prestart() {
return retriableStreamRecorder.prestart();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -587,8 +587,6 @@ final class FakeNameResolver extends NameResolver {

final ServiceConfigParser serviceConfigParser;
Listener2 listener;
boolean shutdown;
int refreshCalled;

FakeNameResolver(ServiceConfigParser serviceConfigParser) {
this.serviceConfigParser = serviceConfigParser;
Expand All @@ -606,7 +604,6 @@ final class FakeNameResolver extends NameResolver {
}

@Override public void refresh() {
refreshCalled++;
resolved();
}

Expand All @@ -623,7 +620,6 @@ void resolved() {
}

@Override public void shutdown() {
shutdown = true;
}

@Override
Expand Down
4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ commons-math3 = "org.apache.commons:commons-math3:3.6.1"
conscrypt = "org.conscrypt:conscrypt-openjdk-uber:2.5.2"
cronet-api = "org.chromium.net:cronet-api:92.4515.131"
cronet-embedded = "org.chromium.net:cronet-embedded:102.5005.125"
errorprone-annotations = "com.google.errorprone:error_prone_annotations:2.14.0"
errorprone-core = "com.google.errorprone:error_prone_core:2.10.0"
errorprone-annotations = "com.google.errorprone:error_prone_annotations:2.18.0"
errorprone-core = "com.google.errorprone:error_prone_core:2.18.0"
google-api-protos = "com.google.api.grpc:proto-google-common-protos:2.9.0"
google-auth-credentials = { module = "com.google.auth:google-auth-library-credentials", version.ref = "googleauth" }
google-auth-oauth2Http = { module = "com.google.auth:google-auth-library-oauth2-http", version.ref = "googleauth" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -633,10 +633,6 @@ public void loadReporting() {

@Test
public void abundantInitialResponse() {
Metadata headers = new Metadata();
PickSubchannelArgs args = mock(PickSubchannelArgs.class);
when(args.getHeaders()).thenReturn(headers);

List<EquivalentAddressGroup> grpclbBalancerList = createResolvedBalancerAddresses(1);
deliverResolvedAddresses(Collections.<EquivalentAddressGroup>emptyList(), grpclbBalancerList);
assertEquals(1, fakeOobChannels.size());
Expand Down Expand Up @@ -719,10 +715,6 @@ public void raceBetweenHandleAddressesAndLbStreamClosure() {

@Test
public void raceBetweenLoadReportingAndLbStreamClosure() {
Metadata headers = new Metadata();
PickSubchannelArgs args = mock(PickSubchannelArgs.class);
when(args.getHeaders()).thenReturn(headers);

List<EquivalentAddressGroup> grpclbBalancerList = createResolvedBalancerAddresses(1);
deliverResolvedAddresses(Collections.<EquivalentAddressGroup>emptyList(), grpclbBalancerList);
assertEquals(1, fakeOobChannels.size());
Expand Down

0 comments on commit 8697f9f

Please sign in to comment.