From ae6c506f962f8d4d8ab850f7a4e488d73fdc1861 Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Wed, 1 Mar 2023 13:45:18 -0800 Subject: [PATCH] all: fix build with errorprone 2.18 (#9886) errorprone cannot be updated past 2.10 because later versions do not support Java 8. Fixes https://github.com/grpc/grpc-java/issues/9916. --- .../internal/AesGcmHkdfAeadCrypterTest.java | 4 +- api/src/main/java/io/grpc/Attributes.java | 1 + api/src/main/java/io/grpc/LoadBalancer.java | 2 +- .../test/java/io/grpc/CallOptionsTest.java | 12 --- .../grpc/benchmarks/TransportBenchmark.java | 1 + .../io/grpc/benchmarks/driver/LoadClient.java | 6 +- .../grpc/benchmarks/qps/OpenLoopClient.java | 2 +- .../io/grpc/census/CensusStatsModule.java | 80 +++++++++++-------- .../io/grpc/internal/InternalSubchannel.java | 6 +- .../internal/JndiResourceResolverFactory.java | 4 +- .../internal/ManagedChannelOrphanWrapper.java | 2 + .../io/grpc/internal/StatsTraceContext.java | 3 +- .../grpc/internal/KeepAliveManagerTest.java | 8 +- .../io/grpc/internal/RetriableStreamTest.java | 7 +- .../ServiceConfigErrorHandlingTest.java | 4 - .../grpc/grpclb/GrpclbLoadBalancerTest.java | 8 -- .../integration/AbstractInteropTest.java | 7 +- .../grpc/testing/integration/Http2Client.java | 6 +- .../testing/integration/XdsTestServer.java | 2 +- .../integration/NettyFlowControlTest.java | 7 -- .../grpc/testing/integration/ProxyTest.java | 4 +- .../io/grpc/testing/istio/EchoTestServer.java | 4 - .../main/java/io/grpc/netty/JettyTlsUtil.java | 11 ++- .../io/grpc/netty/NettyClientHandler.java | 2 +- .../io/grpc/netty/NettyClientStreamTest.java | 1 + .../grpc/netty/NettyClientTransportTest.java | 6 +- .../io/grpc/netty/NettyServerHandlerTest.java | 4 +- .../io/grpc/netty/NettyServerStreamTest.java | 1 + .../okhttp/OkHttpServerTransportTest.java | 16 +--- .../io/grpc/okhttp/OptionalMethodTest.java | 1 + .../java/io/grpc/rls/LinkedHashLruCache.java | 2 +- .../HealthCheckingLoadBalancerFactory.java | 4 - .../xds/ClusterResolverLoadBalancerTest.java | 10 --- .../java/io/grpc/xds/XdsNameResolverTest.java | 6 +- .../io/grpc/xds/XdsServerWrapperTest.java | 29 ++++--- .../test/java/io/grpc/xds/XxHash64Test.java | 2 +- 36 files changed, 113 insertions(+), 162 deletions(-) diff --git a/alts/src/test/java/io/grpc/alts/internal/AesGcmHkdfAeadCrypterTest.java b/alts/src/test/java/io/grpc/alts/internal/AesGcmHkdfAeadCrypterTest.java index d655a6e8358..06f2ff5365f 100644 --- a/alts/src/test/java/io/grpc/alts/internal/AesGcmHkdfAeadCrypterTest.java +++ b/alts/src/test/java/io/grpc/alts/internal/AesGcmHkdfAeadCrypterTest.java @@ -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); @@ -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); diff --git a/api/src/main/java/io/grpc/Attributes.java b/api/src/main/java/io/grpc/Attributes.java index 461ed04d381..ca065765506 100644 --- a/api/src/main/java/io/grpc/Attributes.java +++ b/api/src/main/java/io/grpc/Attributes.java @@ -115,6 +115,7 @@ public Builder toBuilder() { * @param type of the value in the key-value pair */ @Immutable + @SuppressWarnings("UnusedTypeParameter") public static final class Key { private final String debugString; diff --git a/api/src/main/java/io/grpc/LoadBalancer.java b/api/src/main/java/io/grpc/LoadBalancer.java index 6469e33b907..5617d279862 100644 --- a/api/src/main/java/io/grpc/LoadBalancer.java +++ b/api/src/main/java/io/grpc/LoadBalancer.java @@ -772,7 +772,7 @@ public static final class Builder { Builder() { } - private 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; diff --git a/api/src/test/java/io/grpc/CallOptionsTest.java b/api/src/test/java/io/grpc/CallOptionsTest.java index 15e5163e860..f4c98c1369e 100644 --- a/api/src/test/java/io/grpc/CallOptionsTest.java +++ b/api/src/test/java/io/grpc/CallOptionsTest.java @@ -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; @@ -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 { diff --git a/benchmarks/src/jmh/java/io/grpc/benchmarks/TransportBenchmark.java b/benchmarks/src/jmh/java/io/grpc/benchmarks/TransportBenchmark.java index 21f6195075c..ea23fadeec8 100644 --- a/benchmarks/src/jmh/java/io/grpc/benchmarks/TransportBenchmark.java +++ b/benchmarks/src/jmh/java/io/grpc/benchmarks/TransportBenchmark.java @@ -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) diff --git a/benchmarks/src/main/java/io/grpc/benchmarks/driver/LoadClient.java b/benchmarks/src/main/java/io/grpc/benchmarks/driver/LoadClient.java index c9a5812b6a6..6b37718a49b 100644 --- a/benchmarks/src/main/java/io/grpc/benchmarks/driver/LoadClient.java +++ b/benchmarks/src/main/java/io/grpc/benchmarks/driver/LoadClient.java @@ -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 diff --git a/benchmarks/src/main/java/io/grpc/benchmarks/qps/OpenLoopClient.java b/benchmarks/src/main/java/io/grpc/benchmarks/qps/OpenLoopClient.java index f366bc344ff..c44d7b67892 100644 --- a/benchmarks/src/main/java/io/grpc/benchmarks/qps/OpenLoopClient.java +++ b/benchmarks/src/main/java/io/grpc/benchmarks/qps/OpenLoopClient.java @@ -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(); } diff --git a/census/src/main/java/io/grpc/census/CensusStatsModule.java b/census/src/main/java/io/grpc/census/CensusStatsModule.java index 03eaf73570d..78d925a7e26 100644 --- a/census/src/main/java/io/grpc/census/CensusStatsModule.java +++ b/census/src/main/java/io/grpc/census/CensusStatsModule.java @@ -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 @@ -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 @@ -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); } @@ -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 @@ -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 @@ -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); } diff --git a/core/src/main/java/io/grpc/internal/InternalSubchannel.java b/core/src/main/java/io/grpc/internal/InternalSubchannel.java index 4f7c8d1f22f..46582645133 100644 --- a/core/src/main/java/io/grpc/internal/InternalSubchannel.java +++ b/core/src/main/java/io/grpc/internal/InternalSubchannel.java @@ -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); } @@ -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 diff --git a/core/src/main/java/io/grpc/internal/JndiResourceResolverFactory.java b/core/src/main/java/io/grpc/internal/JndiResourceResolverFactory.java index 22e08de9cf4..d9eca2be800 100644 --- a/core/src/main/java/io/grpc/internal/JndiResourceResolverFactory.java +++ b/core/src/main/java/io/grpc/internal/JndiResourceResolverFactory.java @@ -43,6 +43,7 @@ final class JndiResourceResolverFactory implements DnsNameResolver.ResourceResolverFactory { @Nullable + @SuppressWarnings("StaticAssignmentOfThrowable") private static final Throwable JNDI_UNAVAILABILITY_CAUSE = initJndi(); // @UsedReflectively @@ -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. diff --git a/core/src/main/java/io/grpc/internal/ManagedChannelOrphanWrapper.java b/core/src/main/java/io/grpc/internal/ManagedChannelOrphanWrapper.java index aed3a461fb4..32b6cc00878 100644 --- a/core/src/main/java/io/grpc/internal/ManagedChannelOrphanWrapper.java +++ b/core/src/main/java/io/grpc/internal/ManagedChannelOrphanWrapper.java @@ -80,6 +80,8 @@ static final class ManagedChannelReference extends WeakReference refqueue; diff --git a/core/src/main/java/io/grpc/internal/StatsTraceContext.java b/core/src/main/java/io/grpc/internal/StatsTraceContext.java index 33e84e5a0b8..889be30e712 100644 --- a/core/src/main/java/io/grpc/internal/StatsTraceContext.java +++ b/core/src/main/java/io/grpc/internal/StatsTraceContext.java @@ -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. * *

Called from {@link io.grpc.internal.ServerImpl}. */ + @SuppressWarnings("UnusedTypeParameter") public Context serverFilterContext(Context context) { Context ctx = checkNotNull(context, "context"); for (StreamTracer tracer : tracers) { diff --git a/core/src/test/java/io/grpc/internal/KeepAliveManagerTest.java b/core/src/test/java/io/grpc/internal/KeepAliveManagerTest.java index 88002d13558..411a9fbe9fc 100644 --- a/core/src/test/java/io/grpc/internal/KeepAliveManagerTest.java +++ b/core/src/test/java/io/grpc/internal/KeepAliveManagerTest.java @@ -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 statusCaptor = ArgumentCaptor.forClass(Status.class); verify(transport).shutdownNow(statusCaptor.capture()); @@ -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 pingCallbackCaptor = ArgumentCaptor.forClass(ClientTransport.PingCallback.class); verify(transport).ping(pingCallbackCaptor.capture(), isA(Executor.class)); diff --git a/core/src/test/java/io/grpc/internal/RetriableStreamTest.java b/core/src/test/java/io/grpc/internal/RetriableStreamTest.java index 7597c10d354..bbbf36d37c5 100644 --- a/core/src/test/java/io/grpc/internal/RetriableStreamTest.java +++ b/core/src/test/java/io/grpc/internal/RetriableStreamTest.java @@ -162,13 +162,17 @@ private final class RecordedRetriableStream extends RetriableStream { } @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); @@ -178,6 +182,7 @@ ClientStream newSubstream( } @Override + @SuppressWarnings("DirectInvocationOnMock") Status prestart() { return retriableStreamRecorder.prestart(); } diff --git a/core/src/test/java/io/grpc/internal/ServiceConfigErrorHandlingTest.java b/core/src/test/java/io/grpc/internal/ServiceConfigErrorHandlingTest.java index f2f99460286..da3ed7c508e 100644 --- a/core/src/test/java/io/grpc/internal/ServiceConfigErrorHandlingTest.java +++ b/core/src/test/java/io/grpc/internal/ServiceConfigErrorHandlingTest.java @@ -587,8 +587,6 @@ final class FakeNameResolver extends NameResolver { final ServiceConfigParser serviceConfigParser; Listener2 listener; - boolean shutdown; - int refreshCalled; FakeNameResolver(ServiceConfigParser serviceConfigParser) { this.serviceConfigParser = serviceConfigParser; @@ -606,7 +604,6 @@ final class FakeNameResolver extends NameResolver { } @Override public void refresh() { - refreshCalled++; resolved(); } @@ -623,7 +620,6 @@ void resolved() { } @Override public void shutdown() { - shutdown = true; } @Override diff --git a/grpclb/src/test/java/io/grpc/grpclb/GrpclbLoadBalancerTest.java b/grpclb/src/test/java/io/grpc/grpclb/GrpclbLoadBalancerTest.java index 66fd850802c..981ca3fbb3a 100644 --- a/grpclb/src/test/java/io/grpc/grpclb/GrpclbLoadBalancerTest.java +++ b/grpclb/src/test/java/io/grpc/grpclb/GrpclbLoadBalancerTest.java @@ -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 grpclbBalancerList = createResolvedBalancerAddresses(1); deliverResolvedAddresses(Collections.emptyList(), grpclbBalancerList); assertEquals(1, fakeOobChannels.size()); @@ -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 grpclbBalancerList = createResolvedBalancerAddresses(1); deliverResolvedAddresses(Collections.emptyList(), grpclbBalancerList); assertEquals(1, fakeOobChannels.size()); diff --git a/interop-testing/src/main/java/io/grpc/testing/integration/AbstractInteropTest.java b/interop-testing/src/main/java/io/grpc/testing/integration/AbstractInteropTest.java index 76e333be4dd..a8d4776ade9 100644 --- a/interop-testing/src/main/java/io/grpc/testing/integration/AbstractInteropTest.java +++ b/interop-testing/src/main/java/io/grpc/testing/integration/AbstractInteropTest.java @@ -939,7 +939,7 @@ public void fullDuplexCallShouldSucceed() throws Exception { requestStream.onCompleted(); recorder.awaitCompletion(); assertSuccess(recorder); - assertEquals(responseSizes.size() * numRequests, recorder.getValues().size()); + assertEquals(responseSizes.size() * (long) numRequests, recorder.getValues().size()); for (int ix = 0; ix < recorder.getValues().size(); ++ix) { StreamingOutputCallResponse response = recorder.getValues().get(ix); int length = response.getPayload().getBody().size(); @@ -973,7 +973,7 @@ public void halfDuplexCallShouldSucceed() throws Exception { requestStream.onCompleted(); recorder.awaitCompletion(); assertSuccess(recorder); - assertEquals(responseSizes.size() * numRequests, recorder.getValues().size()); + assertEquals(responseSizes.size() * (long) numRequests, recorder.getValues().size()); for (int ix = 0; ix < recorder.getValues().size(); ++ix) { StreamingOutputCallResponse response = recorder.getValues().get(ix); int length = response.getPayload().getBody().size(); @@ -1125,7 +1125,8 @@ public void exchangeMetadataStreamingCall() throws Exception { requestStream.onCompleted(); recorder.awaitCompletion(); assertSuccess(recorder); - org.junit.Assert.assertEquals(responseSizes.size() * numRequests, recorder.getValues().size()); + org.junit.Assert.assertEquals( + responseSizes.size() * (long) numRequests, recorder.getValues().size()); // Assert that our side channel object is echoed back in both headers and trailers Assert.assertEquals(metadataValue, headersCapture.get().get(Util.METADATA_KEY)); diff --git a/interop-testing/src/main/java/io/grpc/testing/integration/Http2Client.java b/interop-testing/src/main/java/io/grpc/testing/integration/Http2Client.java index fbe9e3fa28f..3080748df20 100644 --- a/interop-testing/src/main/java/io/grpc/testing/integration/Http2Client.java +++ b/interop-testing/src/main/java/io/grpc/testing/integration/Http2Client.java @@ -272,7 +272,7 @@ private void maxStreams() throws Exception { threadpool = MoreExecutors.listeningDecorator(newFixedThreadPool(numThreads)); List> workerFutures = new ArrayList<>(); for (int i = 0; i < numThreads; i++) { - workerFutures.add(threadpool.submit(new MaxStreamsWorker(i, simpleRequest))); + workerFutures.add(threadpool.submit(new MaxStreamsWorker(i))); } ListenableFuture f = Futures.allAsList(workerFutures); f.get(timeoutSeconds, TimeUnit.SECONDS); @@ -314,11 +314,9 @@ public boolean awaitCompletion(long timeout, TimeUnit unit) throws Exception { private class MaxStreamsWorker implements Runnable { int threadNum; - SimpleRequest request; - MaxStreamsWorker(int threadNum, SimpleRequest request) { + MaxStreamsWorker(int threadNum) { this.threadNum = threadNum; - this.request = request; } @Override diff --git a/interop-testing/src/main/java/io/grpc/testing/integration/XdsTestServer.java b/interop-testing/src/main/java/io/grpc/testing/integration/XdsTestServer.java index 19a3c44259f..89807b7786d 100644 --- a/interop-testing/src/main/java/io/grpc/testing/integration/XdsTestServer.java +++ b/interop-testing/src/main/java/io/grpc/testing/integration/XdsTestServer.java @@ -338,7 +338,7 @@ public void sendHeaders(Metadata responseHeaders) { try { int timeout = Integer.parseInt( callBehavior.substring(CALL_BEHAVIOR_SLEEP_VALUE.length())); - Thread.sleep(timeout * 1000); + Thread.sleep(timeout * 1000L); } catch (NumberFormatException e) { newCall.close( Status.INVALID_ARGUMENT.withDescription( diff --git a/interop-testing/src/test/java/io/grpc/testing/integration/NettyFlowControlTest.java b/interop-testing/src/test/java/io/grpc/testing/integration/NettyFlowControlTest.java index c94e95704ac..1c8f3bb4a7d 100644 --- a/interop-testing/src/test/java/io/grpc/testing/integration/NettyFlowControlTest.java +++ b/interop-testing/src/test/java/io/grpc/testing/integration/NettyFlowControlTest.java @@ -190,8 +190,6 @@ private void startServer(int serverFlowControlWindow) { private static class TestStreamObserver implements StreamObserver { final AtomicReference grpcHandlerRef; - final long startRequestNanos; - long endRequestNanos; final CountDownLatch latch = new CountDownLatch(1); final long expectedWindow; int lastWindow; @@ -200,7 +198,6 @@ private static class TestStreamObserver implements StreamObserver grpcHandlerRef, long window) { this.grpcHandlerRef = grpcHandlerRef; - startRequestNanos = System.nanoTime(); expectedWindow = window; } @@ -234,10 +231,6 @@ public void onCompleted() { latch.countDown(); } - public long getElapsedTime() { - return endRequestNanos - startRequestNanos; - } - public int waitFor(long duration, TimeUnit unit) throws InterruptedException { latch.await(duration, unit); return lastWindow; diff --git a/interop-testing/src/test/java/io/grpc/testing/integration/ProxyTest.java b/interop-testing/src/test/java/io/grpc/testing/integration/ProxyTest.java index c336ee9aea8..f550d657a12 100644 --- a/interop-testing/src/test/java/io/grpc/testing/integration/ProxyTest.java +++ b/interop-testing/src/test/java/io/grpc/testing/integration/ProxyTest.java @@ -93,7 +93,7 @@ public void smallLatency() throws Exception { } Collections.sort(rtts); long rtt = rtts.get(0); - assertEquals(latency, rtt, .5 * latency); + assertEquals(latency, (double) rtt, .5 * latency); } @Test @@ -126,7 +126,7 @@ public void bigLatency() throws Exception { } Collections.sort(rtts); long rtt = rtts.get(0); - assertEquals(latency, rtt, .5 * latency); + assertEquals(latency, (double) rtt, .5 * latency); } @Test diff --git a/istio-interop-testing/src/main/java/io/grpc/testing/istio/EchoTestServer.java b/istio-interop-testing/src/main/java/io/grpc/testing/istio/EchoTestServer.java index ae6f60098ac..2c6ae38d41a 100644 --- a/istio-interop-testing/src/main/java/io/grpc/testing/istio/EchoTestServer.java +++ b/istio-interop-testing/src/main/java/io/grpc/testing/istio/EchoTestServer.java @@ -494,10 +494,6 @@ void writeKeyValueForRequest(String requestHeader, String key, String value) { } } - void writeMessage(String message) { - sb.append(message); - } - @Override public String toString() { return sb.toString(); diff --git a/netty/src/main/java/io/grpc/netty/JettyTlsUtil.java b/netty/src/main/java/io/grpc/netty/JettyTlsUtil.java index 392aaf8d3e7..8652337bba8 100644 --- a/netty/src/main/java/io/grpc/netty/JettyTlsUtil.java +++ b/netty/src/main/java/io/grpc/netty/JettyTlsUtil.java @@ -34,6 +34,7 @@ private JettyTlsUtil() { private static class Java9AlpnUnavailabilityCauseHolder { + @SuppressWarnings("StaticAssignmentOfThrowable") static final Throwable cause = checkAlpnAvailability(); static Throwable checkAlpnAvailability() { @@ -56,9 +57,8 @@ public Method run() throws Exception { } } - /** - * Indicates whether or not the Jetty ALPN jar is installed in the boot classloader. - */ + /** Indicates whether or not the Jetty ALPN jar is installed in the boot classloader. */ + @SuppressWarnings("StaticAssignmentOfThrowable") static synchronized boolean isJettyAlpnConfigured() { try { Class.forName("org.eclipse.jetty.alpn.ALPN", true, null); @@ -78,9 +78,8 @@ static synchronized Throwable getJettyAlpnUnavailabilityCause() { return jettyAlpnUnavailabilityCause; } - /** - * Indicates whether or not the Jetty NPN jar is installed in the boot classloader. - */ + /** Indicates whether or not the Jetty NPN jar is installed in the boot classloader. */ + @SuppressWarnings("StaticAssignmentOfThrowable") static synchronized boolean isJettyNpnConfigured() { try { Class.forName("org.eclipse.jetty.npn.NextProtoNego", true, null); diff --git a/netty/src/main/java/io/grpc/netty/NettyClientHandler.java b/netty/src/main/java/io/grpc/netty/NettyClientHandler.java index 55337935e3b..1ac14585159 100644 --- a/netty/src/main/java/io/grpc/netty/NettyClientHandler.java +++ b/netty/src/main/java/io/grpc/netty/NettyClientHandler.java @@ -877,7 +877,7 @@ private void cancelPing(Throwable t) { /** If {@code statusCode} is non-null, it will be used instead of the http2 error code mapping. */ private Status statusFromH2Error( Status.Code statusCode, String context, long errorCode, byte[] debugData) { - Status status = GrpcUtil.Http2Error.statusForCode((int) errorCode); + Status status = GrpcUtil.Http2Error.statusForCode(errorCode); if (statusCode == null) { statusCode = status.getCode(); } diff --git a/netty/src/test/java/io/grpc/netty/NettyClientStreamTest.java b/netty/src/test/java/io/grpc/netty/NettyClientStreamTest.java index 01292045657..61525d8369a 100644 --- a/netty/src/test/java/io/grpc/netty/NettyClientStreamTest.java +++ b/netty/src/test/java/io/grpc/netty/NettyClientStreamTest.java @@ -555,6 +555,7 @@ private Http2Headers grpcResponseTrailers(Status status) { } private class TransportStateImpl extends NettyClientStream.TransportState { + @SuppressWarnings("DirectInvocationOnMock") public TransportStateImpl(NettyClientHandler handler, int maxMessageSize) { super( handler, diff --git a/netty/src/test/java/io/grpc/netty/NettyClientTransportTest.java b/netty/src/test/java/io/grpc/netty/NettyClientTransportTest.java index 5f47c7b14c5..a14dca2b278 100644 --- a/netty/src/test/java/io/grpc/netty/NettyClientTransportTest.java +++ b/netty/src/test/java/io/grpc/netty/NettyClientTransportTest.java @@ -887,12 +887,10 @@ public void onReady() { private static final class EchoServerStreamListener implements ServerStreamListener { final ServerStream stream; - final String method; final Metadata headers; - EchoServerStreamListener(ServerStream stream, String method, Metadata headers) { + EchoServerStreamListener(ServerStream stream, Metadata headers) { this.stream = stream; - this.method = method; this.headers = headers; } @@ -932,7 +930,7 @@ public ServerTransportListener transportCreated(final ServerTransport transport) return new ServerTransportListener() { @Override public void streamCreated(ServerStream stream, String method, Metadata headers) { - EchoServerStreamListener listener = new EchoServerStreamListener(stream, method, headers); + EchoServerStreamListener listener = new EchoServerStreamListener(stream, headers); stream.setListener(listener); stream.writeHeaders(new Metadata()); stream.request(1); diff --git a/netty/src/test/java/io/grpc/netty/NettyServerHandlerTest.java b/netty/src/test/java/io/grpc/netty/NettyServerHandlerTest.java index 926ce8261a4..b9edbc517c1 100644 --- a/netty/src/test/java/io/grpc/netty/NettyServerHandlerTest.java +++ b/netty/src/test/java/io/grpc/netty/NettyServerHandlerTest.java @@ -431,7 +431,7 @@ public void shouldAdvertiseMaxConcurrentStreams() throws Exception { verifyWrite().writeSettings( any(ChannelHandlerContext.class), captor.capture(), any(ChannelPromise.class)); - assertEquals(maxConcurrentStreams, captor.getValue().maxConcurrentStreams().intValue()); + assertEquals(maxConcurrentStreams, captor.getValue().maxConcurrentStreams().longValue()); } @Test @@ -443,7 +443,7 @@ public void shouldAdvertiseMaxHeaderListSize() throws Exception { verifyWrite().writeSettings( any(ChannelHandlerContext.class), captor.capture(), any(ChannelPromise.class)); - assertEquals(maxHeaderListSize, captor.getValue().maxHeaderListSize().intValue()); + assertEquals(maxHeaderListSize, captor.getValue().maxHeaderListSize().longValue()); } @Test diff --git a/netty/src/test/java/io/grpc/netty/NettyServerStreamTest.java b/netty/src/test/java/io/grpc/netty/NettyServerStreamTest.java index 4463d55eb74..fe9cd8e03a6 100644 --- a/netty/src/test/java/io/grpc/netty/NettyServerStreamTest.java +++ b/netty/src/test/java/io/grpc/netty/NettyServerStreamTest.java @@ -281,6 +281,7 @@ public void cancelStreamShouldSucceed() { } @Override + @SuppressWarnings("DirectInvocationOnMock") protected NettyServerStream createStream() { when(handler.getWriteQueue()).thenReturn(writeQueue); StatsTraceContext statsTraceCtx = StatsTraceContext.NOOP; diff --git a/okhttp/src/test/java/io/grpc/okhttp/OkHttpServerTransportTest.java b/okhttp/src/test/java/io/grpc/okhttp/OkHttpServerTransportTest.java index af9b7c12d54..b58f21b0a52 100644 --- a/okhttp/src/test/java/io/grpc/okhttp/OkHttpServerTransportTest.java +++ b/okhttp/src/test/java/io/grpc/okhttp/OkHttpServerTransportTest.java @@ -70,7 +70,6 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; import okio.Buffer; import okio.BufferedSource; import okio.ByteString; @@ -130,6 +129,7 @@ public class OkHttpServerTransportTest { @Rule public final Timeout globalTimeout = Timeout.seconds(10); @Before + @SuppressWarnings("DirectInvocationOnMock") public void setUp() throws Exception { doAnswer(answerVoid((Boolean outDone, Integer streamId, BufferedSource in, Integer length) -> { in.require(length); @@ -1294,7 +1294,6 @@ private static class MockStreamListener implements ServerStreamListener { Deque messages = new ArrayDeque<>(); boolean halfClosedCalled; - boolean onReadyCalled; Status status; CountDownLatch closed = new CountDownLatch(1); @@ -1335,19 +1334,6 @@ public void closed(Status status) { @Override public void onReady() { - onReadyCalled = true; - } - - boolean isOnReadyCalled() { - boolean value = onReadyCalled; - onReadyCalled = false; - return value; - } - - void waitUntilStreamClosed() throws InterruptedException, TimeoutException { - if (!closed.await(TIME_OUT_MS, TimeUnit.MILLISECONDS)) { - throw new TimeoutException("Failed waiting stream to be closed."); - } } static String getContent(InputStream message) throws IOException { diff --git a/okhttp/src/test/java/io/grpc/okhttp/OptionalMethodTest.java b/okhttp/src/test/java/io/grpc/okhttp/OptionalMethodTest.java index 1879ce9d6a4..dedf6bc8e44 100644 --- a/okhttp/src/test/java/io/grpc/okhttp/OptionalMethodTest.java +++ b/okhttp/src/test/java/io/grpc/okhttp/OptionalMethodTest.java @@ -50,6 +50,7 @@ public String testMethod(String arg) { } private static class PrivateClass { + @SuppressWarnings("UnusedMethod") public String testMethod(String arg) { return arg; } diff --git a/rls/src/main/java/io/grpc/rls/LinkedHashLruCache.java b/rls/src/main/java/io/grpc/rls/LinkedHashLruCache.java index 77376a374f4..8baba0bb824 100644 --- a/rls/src/main/java/io/grpc/rls/LinkedHashLruCache.java +++ b/rls/src/main/java/io/grpc/rls/LinkedHashLruCache.java @@ -371,7 +371,7 @@ private final class SizeHandlingEvictionListener implements EvictionListener bootstrap; - @Override - public void setBootstrapOverride(Map bootstrap) { - this.bootstrap = bootstrap; - } + public void setBootstrapOverride(Map bootstrap) {} @Override @Nullable diff --git a/xds/src/test/java/io/grpc/xds/XdsServerWrapperTest.java b/xds/src/test/java/io/grpc/xds/XdsServerWrapperTest.java index 6271ca791c6..bd797ce6de9 100644 --- a/xds/src/test/java/io/grpc/xds/XdsServerWrapperTest.java +++ b/xds/src/test/java/io/grpc/xds/XdsServerWrapperTest.java @@ -943,8 +943,8 @@ public void run() { xdsClient.ldsResource.get(5, TimeUnit.SECONDS); verify(mockBuilder).intercept(interceptorCaptor.capture()); ConfigApplyingInterceptor interceptor = interceptorCaptor.getValue(); - ServerRoutingConfig routingConfig = createRoutingConfig("/FooService/barMethod", - "foo.google.com", "filter-type-url"); + ServerRoutingConfig routingConfig = + createRoutingConfig("/FooService/barMethod", "foo.google.com"); ServerCall serverCall = mock(ServerCall.class); when(serverCall.getAttributes()).thenReturn( Attributes.newBuilder().set(ATTR_SERVER_ROUTING_CONFIG, @@ -983,8 +983,8 @@ public void run() { xdsClient.ldsResource.get(5, TimeUnit.SECONDS); verify(mockBuilder).intercept(interceptorCaptor.capture()); ConfigApplyingInterceptor interceptor = interceptorCaptor.getValue(); - ServerRoutingConfig routingConfig = createRoutingConfig("/FooService/barMethod", - "foo.google.com", "filter-type-url"); + ServerRoutingConfig routingConfig = + createRoutingConfig("/FooService/barMethod", "foo.google.com"); ServerCall serverCall = mock(ServerCall.class); when(serverCall.getAttributes()).thenReturn( Attributes.newBuilder() @@ -1024,10 +1024,12 @@ public void run() { xdsClient.ldsResource.get(5, TimeUnit.SECONDS); verify(mockBuilder).intercept(interceptorCaptor.capture()); ConfigApplyingInterceptor interceptor = interceptorCaptor.getValue(); - ServerRoutingConfig routingConfig = createRoutingConfig("/FooService/barMethod", - "foo.google.com", "filter-type-url", Route.RouteAction.forCluster( - "cluster", Collections.emptyList(), null, null - )); + ServerRoutingConfig routingConfig = + createRoutingConfig( + "/FooService/barMethod", + "foo.google.com", + Route.RouteAction.forCluster( + "cluster", Collections.emptyList(), null, null)); ServerCall serverCall = mock(ServerCall.class); when(serverCall.getAttributes()).thenReturn( Attributes.newBuilder() @@ -1286,13 +1288,12 @@ private static EnvoyServerProtoData.FilterChainMatch createMatch() { ""); } - private static ServerRoutingConfig createRoutingConfig(String path, String domain, - String filterType) { - return createRoutingConfig(path, domain, filterType, null); + private static ServerRoutingConfig createRoutingConfig(String path, String domain) { + return createRoutingConfig(path, domain, null); } - private static ServerRoutingConfig createRoutingConfig(String path, String domain, - String filterType, Route.RouteAction action) { + private static ServerRoutingConfig createRoutingConfig( + String path, String domain, Route.RouteAction action) { RouteMatch routeMatch = RouteMatch.create( PathMatcher.fromPath(path, true), @@ -1302,8 +1303,6 @@ private static ServerRoutingConfig createRoutingConfig(String path, String domai Arrays.asList(Route.forAction(routeMatch, action, ImmutableMap.of())), Collections.emptyMap()); - FilterConfig f0 = mock(FilterConfig.class); - when(f0.typeUrl()).thenReturn(filterType); return ServerRoutingConfig.create(ImmutableList.of(virtualHost), ImmutableMap.of() ); diff --git a/xds/third_party/zero-allocation-hashing/test/java/io/grpc/xds/XxHash64Test.java b/xds/third_party/zero-allocation-hashing/test/java/io/grpc/xds/XxHash64Test.java index d66c8cf9d97..10219a2f72e 100644 --- a/xds/third_party/zero-allocation-hashing/test/java/io/grpc/xds/XxHash64Test.java +++ b/xds/third_party/zero-allocation-hashing/test/java/io/grpc/xds/XxHash64Test.java @@ -136,7 +136,7 @@ private static void testNegativePrimitives(XxHash64 f, int len) { long eightByteExpected = f.hashBytes(bytes); assertEquals("byte hash", oneByteExpected, f.hashByte((byte) -1)); assertEquals("short hash", twoByteExpected, f.hashShort((short) -1)); - assertEquals("char hash", twoByteExpected, f.hashChar((char) -1)); + assertEquals("char hash", twoByteExpected, f.hashChar(Character.MAX_VALUE)); assertEquals("int hash", fourByteExpected, f.hashInt(-1)); assertEquals("long hash", eightByteExpected, f.hashLong(-1L)); }