From 2eeb5e3e9eb9cb9fffdae8700925b3b7219381d9 Mon Sep 17 00:00:00 2001 From: Eric Anderson Date: Thu, 23 Feb 2017 17:02:31 -0800 Subject: [PATCH] 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. --- android-interop-testing/app/build.gradle | 3 - build.gradle | 2 +- .../grpc/internal/LogExceptionRunnable.java | 3 +- .../java/io/grpc/internal/MoreThrowables.java | 56 +++++++++++++++++++ .../java/io/grpc/internal/ServerCallImpl.java | 3 +- examples/android/helloworld/app/build.gradle | 3 - examples/android/routeguide/app/build.gradle | 3 - .../integration/AbstractInteropTest.java | 2 +- 8 files changed, 60 insertions(+), 15 deletions(-) create mode 100644 core/src/main/java/io/grpc/internal/MoreThrowables.java diff --git a/android-interop-testing/app/build.gradle b/android-interop-testing/app/build.gradle index 587b2e0fc3..4ab70edc71 100644 --- a/android-interop-testing/app/build.gradle +++ b/android-interop-testing/app/build.gradle @@ -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 diff --git a/build.gradle b/build.gradle index 1b02c1985b..f4ab1f787f 100644 --- a/build.gradle +++ b/build.gradle @@ -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' diff --git a/core/src/main/java/io/grpc/internal/LogExceptionRunnable.java b/core/src/main/java/io/grpc/internal/LogExceptionRunnable.java index 5bf192b86b..835c1cd882 100644 --- a/core/src/main/java/io/grpc/internal/LogExceptionRunnable.java +++ b/core/src/main/java/io/grpc/internal/LogExceptionRunnable.java @@ -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); } } diff --git a/core/src/main/java/io/grpc/internal/MoreThrowables.java b/core/src/main/java/io/grpc/internal/MoreThrowables.java new file mode 100644 index 0000000000..2792218478 --- /dev/null +++ b/core/src/main/java/io/grpc/internal/MoreThrowables.java @@ -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}. + * + *

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() {} +} diff --git a/core/src/main/java/io/grpc/internal/ServerCallImpl.java b/core/src/main/java/io/grpc/internal/ServerCallImpl.java index fad2b700cd..3584a45976 100644 --- a/core/src/main/java/io/grpc/internal/ServerCallImpl.java +++ b/core/src/main/java/io/grpc/internal/ServerCallImpl.java @@ -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 extends ServerCall { } finally { if (t != null) { // TODO(carl-mastrangelo): Maybe log e here. - Throwables.throwIfUnchecked(t); + MoreThrowables.throwIfUnchecked(t); throw new RuntimeException(t); } } diff --git a/examples/android/helloworld/app/build.gradle b/examples/android/helloworld/app/build.gradle index d7637141fc..0587bc6168 100644 --- a/examples/android/helloworld/app/build.gradle +++ b/examples/android/helloworld/app/build.gradle @@ -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 diff --git a/examples/android/routeguide/app/build.gradle b/examples/android/routeguide/app/build.gradle index a2a48c7058..739aa4ac6e 100644 --- a/examples/android/routeguide/app/build.gradle +++ b/examples/android/routeguide/app/build.gradle @@ -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 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 2b8c51b305..39657923ee 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 @@ -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()} */