The driver is compatible with Guava 16.0.1 or higher, but Guava 20 introduced incompatible
- * breaking changes in its API, that could in turn be breaking for legacy driver clients if we
- * simply upgraded our dependency. We don't want to increment our major version "just" for Guava (we
- * have other changes planned).
+ *
The driver is compatible with Guava 19.0 or higher.
*
- *
Therefore we depend on Guava 19, which has both the deprecated and the new APIs, and detect
- * the actual version at runtime in order to call the relevant methods.
+ *
We detect the actual version at runtime in order to call the relevant methods.
*
*
This is a hack, and might not work with subsequent Guava releases; the real fix is to stop
* exposing Guava in our public API. We'll address that in version 4 of the driver.
@@ -188,84 +179,18 @@ public abstract ListenableFuture transformAsync(
*
The method {@code HostAndPort.getHostText} has been replaced with {@code
* HostAndPort.getHost} starting with Guava 20.0; it has been completely removed in Guava 22.0.
*/
- @SuppressWarnings("JavaReflectionMemberAccess")
public String getHost(HostAndPort hostAndPort) {
- try {
- // Guava >= 20.0
- return (String) HostAndPort.class.getMethod("getHost").invoke(hostAndPort);
- } catch (Exception e) {
- // Guava < 22.0
- return hostAndPort.getHostText();
- }
+ // Guava >= 20.0
+ return hostAndPort.getHost();
}
private static GuavaCompatibility selectImplementation() {
if (isGuava_19_0_OrHigher()) {
logger.info("Detected Guava >= 19 in the classpath, using modern compatibility layer");
return new Version19OrHigher();
- } else if (isGuava_16_0_1_OrHigher()) {
- logger.info("Detected Guava < 19 in the classpath, using legacy compatibility layer");
- return new Version18OrLower();
} else {
throw new DriverInternalError(
- "Detected incompatible version of Guava in the classpath. "
- + "You need 16.0.1 or higher.");
- }
- }
-
- private static class Version18OrLower extends GuavaCompatibility {
-
- @Override
- public ListenableFuture withFallback(
- ListenableFuture extends V> input, final AsyncFunction fallback) {
- return Futures.withFallback(
- input,
- new com.google.common.util.concurrent.FutureFallback() {
- @Override
- public ListenableFuture create(Throwable t) throws Exception {
- return fallback.apply(t);
- }
- });
- }
-
- @Override
- public ListenableFuture withFallback(
- ListenableFuture extends V> input,
- final AsyncFunction fallback,
- Executor executor) {
- return Futures.withFallback(
- input,
- new com.google.common.util.concurrent.FutureFallback() {
- @Override
- public ListenableFuture create(Throwable t) throws Exception {
- return fallback.apply(t);
- }
- },
- executor);
- }
-
- @Override
- public ListenableFuture transformAsync(
- ListenableFuture input, AsyncFunction super I, ? extends O> function) {
- return Futures.transform(input, function);
- }
-
- @Override
- public ListenableFuture transformAsync(
- ListenableFuture input,
- AsyncFunction super I, ? extends O> function,
- Executor executor) {
- return Futures.transform(input, function, executor);
- }
-
- @Override
- public boolean isSupertypeOf(TypeToken> target, TypeToken> argument) {
- return target.isAssignableFrom(argument);
- }
-
- @Override
- public Executor sameThreadExecutor() {
- return MoreExecutors.sameThreadExecutor();
+ "Detected incompatible version of Guava in the classpath. " + "You need 19.0 or higher.");
}
}
@@ -319,30 +244,6 @@ private static boolean isGuava_19_0_OrHigher() {
Executor.class);
}
- private static boolean isGuava_16_0_1_OrHigher() {
- // Cheap check for < 16.0
- if (!methodExists(Maps.class, "asConverter", BiMap.class)) {
- return false;
- }
- // More elaborate check to filter out 16.0, which has a bug in TypeToken. We need 16.0.1.
- boolean resolved = false;
- TypeToken