Update ErrorProne to 2.1.3 and fix failures

The fixes could have subtle side-effects, but I did take care when making them.
This commit is contained in:
Eric Anderson 2018-01-08 15:08:56 -08:00
parent c96ce4de20
commit 4bc0c95d0b
11 changed files with 29 additions and 23 deletions

View File

@ -137,7 +137,7 @@ public class OpenLoopClient {
stub = BenchmarkServiceGrpc.newStub(checkNotNull(channel, "channel")); stub = BenchmarkServiceGrpc.newStub(checkNotNull(channel, "channel"));
this.request = checkNotNull(request, "request"); this.request = checkNotNull(request, "request");
this.targetQps = targetQps; this.targetQps = targetQps;
numRpcs = targetQps * duration; numRpcs = (long) targetQps * duration;
rnd = new Random(); rnd = new Random();
} }

View File

@ -35,7 +35,7 @@ subprojects {
dependencies { dependencies {
// The ErrorProne plugin defaults to the latest, which would break our // The ErrorProne plugin defaults to the latest, which would break our
// build if error prone releases a new version with a new check // build if error prone releases a new version with a new check
errorprone 'com.google.errorprone:error_prone_core:2.0.21' errorprone 'com.google.errorprone:error_prone_core:2.1.3'
apt 'com.google.guava:guava-beta-checker:1.0' apt 'com.google.guava:guava-beta-checker:1.0'
} }
} else { } else {
@ -76,7 +76,8 @@ subprojects {
compileTestJava { compileTestJava {
// serialVersionUID is basically guaranteed to be useless in our tests // serialVersionUID is basically guaranteed to be useless in our tests
options.compilerArgs += ["-Xlint:-serial"] // LinkedList doesn't hurt much in tests and has lots of usages
options.compilerArgs += ["-Xlint:-serial", "-Xep:JdkObsolete:OFF"]
} }
jar.manifest { jar.manifest {

View File

@ -24,13 +24,13 @@ import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.google.common.io.BaseEncoding; import com.google.common.io.BaseEncoding;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.BitSet; import java.util.BitSet;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
@ -347,7 +347,7 @@ public final class Metadata {
List<T> ret = null; List<T> ret = null;
for (; readIdx < size; readIdx++) { for (; readIdx < size; readIdx++) {
if (bytesEqual(key.asciiName(), name(readIdx))) { if (bytesEqual(key.asciiName(), name(readIdx))) {
ret = ret != null ? ret : new LinkedList<T>(); ret = ret != null ? ret : new ArrayList<T>();
ret.add(key.parseBytes(value(readIdx))); ret.add(key.parseBytes(value(readIdx)));
continue; continue;
} }

View File

@ -20,7 +20,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
import io.grpc.Decompressor; import io.grpc.Decompressor;
import java.io.InputStream; import java.io.InputStream;
import java.util.LinkedList; import java.util.ArrayDeque;
import java.util.Queue; import java.util.Queue;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@ -41,7 +41,7 @@ public class ApplicationThreadDeframer implements Deframer, MessageDeframer.List
private final TransportExecutor transportExecutor; private final TransportExecutor transportExecutor;
/** Queue for messages returned by the deframer when deframing in the application thread. */ /** Queue for messages returned by the deframer when deframing in the application thread. */
private final Queue<InputStream> messageReadQueue = new LinkedList<InputStream>(); private final Queue<InputStream> messageReadQueue = new ArrayDeque<InputStream>();
ApplicationThreadDeframer( ApplicationThreadDeframer(
MessageDeframer.Listener listener, MessageDeframer.Listener listener,

View File

@ -19,7 +19,8 @@ package io.grpc.internal;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.annotations.VisibleForTesting; import com.google.common.annotations.VisibleForTesting;
import java.util.LinkedList; import java.util.ArrayDeque;
import java.util.Queue;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import javax.annotation.concurrent.GuardedBy; import javax.annotation.concurrent.GuardedBy;
@ -39,7 +40,7 @@ final class ChannelExecutor {
private final Object lock = new Object(); private final Object lock = new Object();
@GuardedBy("lock") @GuardedBy("lock")
private final LinkedList<Runnable> queue = new LinkedList<Runnable>(); private final Queue<Runnable> queue = new ArrayDeque<Runnable>();
@GuardedBy("lock") @GuardedBy("lock")
private boolean draining; private boolean draining;

View File

@ -21,7 +21,9 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import io.grpc.MethodDescriptor.MethodType; import io.grpc.MethodDescriptor.MethodType;
import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.junit.runners.JUnit4; import org.junit.runners.JUnit4;
@ -30,6 +32,9 @@ import org.junit.runners.JUnit4;
*/ */
@RunWith(JUnit4.class) @RunWith(JUnit4.class)
public class MethodDescriptorTest { public class MethodDescriptorTest {
@Rule
public final ExpectedException thrown = ExpectedException.none();
@Test @Test
public void createMethodDescriptor() { public void createMethodDescriptor() {
@SuppressWarnings("deprecation") // MethodDescriptor.create @SuppressWarnings("deprecation") // MethodDescriptor.create
@ -80,7 +85,7 @@ public class MethodDescriptorTest {
assertEquals("package.service/method", newDescriptor.getFullMethodName()); assertEquals("package.service/method", newDescriptor.getFullMethodName());
} }
@Test(expected = IllegalArgumentException.class) @Test
public void safeAndNonUnary() { public void safeAndNonUnary() {
MethodDescriptor<String, String> descriptor = MethodDescriptor.<String, String>newBuilder() MethodDescriptor<String, String> descriptor = MethodDescriptor.<String, String>newBuilder()
.setType(MethodType.SERVER_STREAMING) .setType(MethodType.SERVER_STREAMING)
@ -89,10 +94,8 @@ public class MethodDescriptorTest {
.setResponseMarshaller(new StringMarshaller()) .setResponseMarshaller(new StringMarshaller())
.build(); .build();
thrown.expect(IllegalArgumentException.class);
MethodDescriptor<String, String> discard = descriptor.toBuilder().setSafe(true).build(); MethodDescriptor<String, String> unused = descriptor.toBuilder().setSafe(true).build();
// Never reached
assert discard == null;
} }
@Test @Test

View File

@ -39,9 +39,9 @@ import io.grpc.testing.integration.Messages.StreamingOutputCallRequest;
import io.grpc.testing.integration.Messages.StreamingOutputCallResponse; import io.grpc.testing.integration.Messages.StreamingOutputCallResponse;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.ArrayDeque;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashSet; import java.util.HashSet;
import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Queue; import java.util.Queue;
import java.util.Random; import java.util.Random;
@ -209,7 +209,7 @@ public class TestServiceImpl extends TestServiceGrpc.TestServiceImplBase {
@Override @Override
public StreamObserver<Messages.StreamingOutputCallRequest> halfDuplexCall( public StreamObserver<Messages.StreamingOutputCallRequest> halfDuplexCall(
final StreamObserver<Messages.StreamingOutputCallResponse> responseObserver) { final StreamObserver<Messages.StreamingOutputCallResponse> responseObserver) {
final Queue<Chunk> chunks = new LinkedList<Chunk>(); final Queue<Chunk> chunks = new ArrayDeque<Chunk>();
return new StreamObserver<StreamingOutputCallRequest>() { return new StreamObserver<StreamingOutputCallRequest>() {
@Override @Override
public void onNext(StreamingOutputCallRequest request) { public void onNext(StreamingOutputCallRequest request) {
@ -371,7 +371,7 @@ public class TestServiceImpl extends TestServiceGrpc.TestServiceImplBase {
* Breaks down the request and creates a queue of response chunks for the given request. * Breaks down the request and creates a queue of response chunks for the given request.
*/ */
public Queue<Chunk> toChunkQueue(StreamingOutputCallRequest request) { public Queue<Chunk> toChunkQueue(StreamingOutputCallRequest request) {
Queue<Chunk> chunkQueue = new LinkedList<Chunk>(); Queue<Chunk> chunkQueue = new ArrayDeque<Chunk>();
int offset = 0; int offset = 0;
boolean compressable = compressableResponse(request.getResponseType()); boolean compressable = compressableResponse(request.getResponseType());
for (ResponseParameters params : request.getResponseParametersList()) { for (ResponseParameters params : request.getResponseParametersList()) {

View File

@ -50,8 +50,8 @@ public class AbstractHttp2HeadersTest {
} catch (InvocationTargetException ex) { } catch (InvocationTargetException ex) {
assertEquals("For method: " + method, assertEquals("For method: " + method,
UnsupportedOperationException.class, ex.getCause().getClass()); UnsupportedOperationException.class, ex.getCause().getClass());
} catch (Throwable t) { } catch (Exception ex) {
throw new RuntimeException("Failure with method: " + method, t); throw new AssertionError("Failure with method: " + method, ex);
} }
} }
} }

View File

@ -165,6 +165,7 @@ class OkHttpClientTransport implements ConnectionClientTransport {
private Socket socket; private Socket socket;
@GuardedBy("lock") @GuardedBy("lock")
private int maxConcurrentStreams = 0; private int maxConcurrentStreams = 0;
@SuppressWarnings("JdkObsolete") // Usage is bursty; want low memory usage when empty
@GuardedBy("lock") @GuardedBy("lock")
private LinkedList<OkHttpClientStream> pendingStreams = new LinkedList<OkHttpClientStream>(); private LinkedList<OkHttpClientStream> pendingStreams = new LinkedList<OkHttpClientStream>();
private final ConnectionSpec connectionSpec; private final ConnectionSpec connectionSpec;

View File

@ -42,10 +42,10 @@ import io.grpc.reflection.v1alpha.ServerReflectionResponse;
import io.grpc.reflection.v1alpha.ServiceResponse; import io.grpc.reflection.v1alpha.ServiceResponse;
import io.grpc.stub.ServerCallStreamObserver; import io.grpc.stub.ServerCallStreamObserver;
import io.grpc.stub.StreamObserver; import io.grpc.stub.StreamObserver;
import java.util.ArrayDeque;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Queue; import java.util.Queue;
@ -300,7 +300,7 @@ public final class ProtoReflectionService extends ServerReflectionGrpc.ServerRef
FileDescriptorResponse.Builder fdRBuilder = FileDescriptorResponse.newBuilder(); FileDescriptorResponse.Builder fdRBuilder = FileDescriptorResponse.newBuilder();
Set<String> seenFiles = new HashSet<String>(); Set<String> seenFiles = new HashSet<String>();
Queue<FileDescriptor> frontier = new LinkedList<FileDescriptor>(); Queue<FileDescriptor> frontier = new ArrayDeque<FileDescriptor>();
seenFiles.add(fd.getName()); seenFiles.add(fd.getName());
frontier.add(fd); frontier.add(fd);
while (!frontier.isEmpty()) { while (!frontier.isEmpty()) {
@ -408,7 +408,7 @@ public final class ProtoReflectionService extends ServerReflectionGrpc.ServerRef
new HashMap<String, Map<Integer, FileDescriptor>>(); new HashMap<String, Map<Integer, FileDescriptor>>();
FileDescriptorIndex(List<ServerServiceDefinition> services) { FileDescriptorIndex(List<ServerServiceDefinition> services) {
Queue<FileDescriptor> fileDescriptorsToProcess = new LinkedList<FileDescriptor>(); Queue<FileDescriptor> fileDescriptorsToProcess = new ArrayDeque<FileDescriptor>();
Set<String> seenFiles = new HashSet<String>(); Set<String> seenFiles = new HashSet<String>();
for (ServerServiceDefinition service : services) { for (ServerServiceDefinition service : services) {
io.grpc.ServiceDescriptor serviceDescriptor = service.getServiceDescriptor(); io.grpc.ServiceDescriptor serviceDescriptor = service.getServiceDescriptor();

View File

@ -557,7 +557,7 @@ public class ClientCallsTest {
try { try {
iter.next(); iter.next();
fail("Should fail"); fail("Should fail");
} catch (Throwable e) { } catch (Exception e) {
Status status = Status.fromThrowable(e); Status status = Status.fromThrowable(e);
assertEquals(Status.INTERNAL, status); assertEquals(Status.INTERNAL, status);
Metadata metadata = Status.trailersFromThrowable(e); Metadata metadata = Status.trailersFromThrowable(e);