all: Downgrade to Guava 19

Guava 20 introduced some overloading optimizations for Preconditions
that require using Guava 20+ at runtime. Unfortunately, Guava 20 removes
some things that is causing incompatibilities with other libraries, like
Cassandra. While the incompatibility did trigger some of those libraries
to improve compatibility for newer Guavas, we'd like to give the
community more time to work through it. See #2688

At this commit, we appear to be compatible with Guava 18+. It's not
clear if we want to actually "support" 18, but it did compile. Guava 17
doesn't have at least MoreObjects, directExecutor, and firstNotNull.
Guava 21 compiles without warnings, so it should be compatible with
Guava 22 when it is released.

One test method will fail with the upcoming Guava 22, but this won't
impact applications. I made MoreThrowables to avoid using any
known-deprecated Guava methods in our JARs, to reduce pain for those
stuck with old versions of gRPC in the future (July 2018).

In the stand-alone Android apps I removed unnecessary explicit deps
instead of syncing the version used.
This commit is contained in:
Eric Anderson 2017-02-23 17:02:31 -08:00
parent e67b6027af
commit 2eeb5e3e9e
8 changed files with 60 additions and 15 deletions

View File

@ -57,9 +57,6 @@ protobuf {
dependencies {
compile 'com.android.support:appcompat-v7:22.1.1'
compile 'com.google.android.gms:play-services-base:7.3.0'
compile 'com.google.code.findbugs:jsr305:3.0.0'
compile 'com.google.guava:guava:18.0'
compile 'com.squareup.okhttp:okhttp:2.2.0'
// You need to build grpc-java to obtain these libraries below.
compile 'io.grpc:grpc-protobuf-nano:1.2.0-SNAPSHOT' // CURRENT_GRPC_VERSION
compile 'io.grpc:grpc-okhttp:1.2.0-SNAPSHOT' // CURRENT_GRPC_VERSION

View File

@ -71,7 +71,7 @@ subprojects {
protocPluginBaseName = 'protoc-gen-grpc-java'
javaPluginPath = "$rootDir/compiler/build/exe/java_plugin/$protocPluginBaseName$exeSuffix"
guavaVersion = '20.0'
guavaVersion = '19.0'
protobufVersion = '3.2.0'
protobufNanoVersion = '3.0.0-alpha-5'

View File

@ -33,7 +33,6 @@ package io.grpc.internal;
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.base.Throwables;
import java.util.logging.Level;
import java.util.logging.Logger;
@ -57,7 +56,7 @@ public final class LogExceptionRunnable implements Runnable {
task.run();
} catch (Throwable t) {
log.log(Level.SEVERE, "Exception while executing runnable " + task, t);
Throwables.throwIfUnchecked(t);
MoreThrowables.throwIfUnchecked(t);
throw new AssertionError(t);
}
}

View File

@ -0,0 +1,56 @@
/*
* Copyright 2017, Google Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package io.grpc.internal;
import com.google.common.base.Preconditions;
/** Utility functions when interacting with {@link Throwables}. */
final class MoreThrowables {
/**
* Throws {code t} if it is an instance of {@link RuntimeException} or {@link Error}.
*
* <p>This is intended to mimic Guava's method by the same name, but which is unavailable to us
* due to compatibility with older Guava versions.
*/
public static void throwIfUnchecked(Throwable t) {
Preconditions.checkNotNull(t);
if (t instanceof RuntimeException) {
throw (RuntimeException) t;
}
if (t instanceof Error) {
throw (Error) t;
}
}
// Prevent instantiation
private MoreThrowables() {}
}

View File

@ -39,7 +39,6 @@ import static io.grpc.internal.GrpcUtil.MESSAGE_ACCEPT_ENCODING_KEY;
import static io.grpc.internal.GrpcUtil.MESSAGE_ENCODING_KEY;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Throwables;
import io.grpc.Attributes;
import io.grpc.Codec;
import io.grpc.Compressor;
@ -248,7 +247,7 @@ final class ServerCallImpl<ReqT, RespT> extends ServerCall<ReqT, RespT> {
} finally {
if (t != null) {
// TODO(carl-mastrangelo): Maybe log e here.
Throwables.throwIfUnchecked(t);
MoreThrowables.throwIfUnchecked(t);
throw new RuntimeException(t);
}
}

View File

@ -52,9 +52,6 @@ protobuf {
dependencies {
compile 'com.android.support:appcompat-v7:22.1.1'
compile 'com.google.code.findbugs:jsr305:3.0.0'
compile 'com.google.guava:guava:20.0'
compile 'com.squareup.okhttp:okhttp:2.2.0'
// You need to build grpc-java to obtain these libraries below.
compile 'io.grpc:grpc-okhttp:1.2.0-SNAPSHOT' // CURRENT_GRPC_VERSION

View File

@ -50,9 +50,6 @@ protobuf {
dependencies {
compile 'com.android.support:appcompat-v7:23.+'
compile 'com.google.code.findbugs:jsr305:3.0.0'
compile 'com.google.guava:guava:20.0'
compile 'com.squareup.okhttp:okhttp:2.2.0'
// You need to build grpc-java to obtain these libraries below.
compile 'io.grpc:grpc-okhttp:1.2.0-SNAPSHOT' // CURRENT_GRPC_VERSION

View File

@ -1254,7 +1254,7 @@ public abstract class AbstractInteropTest {
HostAndPort remoteAddress = HostAndPort.fromString(serverCallCapture.get().getAttributes()
.get(Grpc.TRANSPORT_ATTR_REMOTE_ADDR).toString());
assertEquals(expectedRemoteAddress, remoteAddress.getHost());
assertEquals(expectedRemoteAddress, remoteAddress.getHostText());
}
/** Helper for asserting TLS info in SSLSession {@link io.grpc.ServerCall#getAttributes()} */