Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

all: Downgrade to Guava 19 #2751

Merged
merged 2 commits into from
Feb 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions android-interop-testing/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,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'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@

import static com.google.common.base.Preconditions.checkNotNull;

import com.google.common.base.Throwables;
import java.util.logging.Level;
import java.util.logging.Logger;

Expand All @@ -57,7 +56,7 @@ public void run() {
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);
}
}
Expand Down
57 changes: 57 additions & 0 deletions core/src/main/java/io/grpc/internal/MoreThrowables.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* 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}. */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: remove this when upgrading.

// TODO(ejona): Delete this once we've upgraded to Guava 20 or later.
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() {}
}
3 changes: 1 addition & 2 deletions core/src/main/java/io/grpc/internal/ServerCallImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
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;
Expand Down Expand Up @@ -247,7 +246,7 @@ public void messageRead(final InputStream message) {
} finally {
if (t != null) {
// TODO(carl-mastrangelo): Maybe log e here.
Throwables.throwIfUnchecked(t);
MoreThrowables.throwIfUnchecked(t);
throw new RuntimeException(t);
}
}
Expand Down
3 changes: 0 additions & 3 deletions examples/android/helloworld/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions examples/android/routeguide/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
import com.google.common.base.Throwables;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import com.google.common.net.HostAndPort;
import com.google.instrumentation.stats.RpcConstants;
import com.google.instrumentation.stats.StatsContextFactory;
import com.google.instrumentation.stats.TagValue;
Expand Down Expand Up @@ -1252,9 +1251,12 @@ protected void assertRemoteAddr(String expectedRemoteAddress) {

stub.unaryCall(SimpleRequest.getDefaultInstance());

HostAndPort remoteAddress = HostAndPort.fromString(serverCallCapture.get().getAttributes()
.get(Grpc.TRANSPORT_ATTR_REMOTE_ADDR).toString());
assertEquals(expectedRemoteAddress, remoteAddress.getHost());
String inetSocketString = serverCallCapture.get().getAttributes()
.get(Grpc.TRANSPORT_ATTR_REMOTE_ADDR).toString();
// The substring is simply host:port, even if host is IPv6 as it fails to use []. Can't use
// standard parsing because the string isn't following any standard.
String host = inetSocketString.substring(0, inetSocketString.lastIndexOf(':'));
assertEquals(expectedRemoteAddress, host);
}

/** Helper for asserting TLS info in SSLSession {@link io.grpc.ServerCall#getAttributes()} */
Expand Down