javacassandraguavadatastax-enterprisedatastax-java-driver

Class not found com/google/common/util/concurrent/FutureFallback


I am getting this error when I try to connect to Cassandra from Java using DataStax Java Driver. I have read few answer on SO. Here it says com.google.common.util.concurrent.FutureFallback is deprecated in Guava 19.0 and removed since Guava 20.0. So, do not use Guava 20.0 or greater.

Moreover, I am using Pmml-Evaluator which requires Guava 20.0. My code works fine if I remove this code of connecting to Cassandra. So, how do i resolve this now?

Pom.xml dependencies :

<dependencies>

    <dependency>
      <groupId>org.jpmml</groupId>
      <artifactId>pmml-model</artifactId>
      <version>1.3.4</version>
   </dependency>

     <dependency>
        <groupId>com.beust</groupId>
        <artifactId>jcommander</artifactId>
        <version>1.48</version>
      </dependency>

    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>3.8.1</version>
        <scope>test</scope>
    </dependency>

     <dependency>
        <groupId>org.jpmml</groupId>
        <artifactId>pmml-evaluator</artifactId>
        <version>1.3.4</version>
      </dependency>

   <dependency>
      <groupId>io.grpc</groupId>
      <artifactId>grpc-netty</artifactId>
      <version>1.1.2</version>
    </dependency>

  <dependency>
    <groupId>io.grpc</groupId>
    <artifactId>grpc-protobuf</artifactId>
    <version>1.1.2</version>
  </dependency>

  <dependency>
    <groupId>io.grpc</groupId>
    <artifactId>grpc-stub</artifactId>
    <version>1.1.2</version>
  </dependency>

  <dependency>
    <groupId>io.netty</groupId>
    <artifactId>netty-handler</artifactId>
    <version>4.1.8.Final</version>
</dependency>

  <dependency>
      <groupId>com.datastax.cassandra</groupId>
      <artifactId>cassandra-driver-core</artifactId>
      <version>3.1.4</version>
  </dependency>

  </dependencies> 

Class :

package com.cw.predictive;

import com.datastax.driver.core.Session;
import com.datastax.driver.core.Cluster;

public class CassandraSession {

    private static Session session;

    private CassandraSession(){}

    public static Session getCassandraSessionInstance(String[] CONTACT_POINTS, int PORT){

        if(session == null){                    
            synchronized (Session.class) {
                if(session == null){                   
                    try{                                        
                         Cluster cluster = Cluster.builder()
                        .addContactPoints(CONTACT_POINTS).withPort(PORT)
                        .build();                                              
                         session = cluster.connect();
                    }
                    catch(Exception ex) {
                        System.out.println("Error occurred");
                        return null;            
                    }               
                }             
            }           
        }       
        return session;
    }
} 

Error:

Exception in thread "grpc-default-executor-0" java.lang.NoClassDefFoundError: com/google/common/util/concurrent/FutureFallback
        at com.cw.predictive.CassandraSession.getCassandraSessionInstance(CassandraSession.java:18)
        at com.cw.predictive.PredictiveScore$LeadScoreImpl.getLeadScore(PredictiveScore.java:136)
        at com.cw.predicitivegrpc.LeadScoreGrpc$MethodHandlers.invoke(LeadScoreGrpc.java:234)
        at io.grpc.stub.ServerCalls$1$1.onHalfClose(ServerCalls.java:148)
        at io.grpc.internal.ServerCallImpl$ServerStreamListenerImpl.halfClosed(ServerCallImpl.java:263)
        at io.grpc.internal.ServerImpl$JumpToApplicationThreadServerStreamListener$2.runInContext(ServerImpl.java:586)
        at io.grpc.internal.ContextRunnable.run(ContextRunnable.java:52)
        at io.grpc.internal.SerializingExecutor$TaskRunner.run(SerializingExecutor.java:152)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at java.lang.Thread.run(Thread.java:745)
    Caused by: java.lang.ClassNotFoundException: com.google.common.util.concurrent.FutureFallback
        at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
        ... 11 more

Solution

  • As you have encountered, the DataStax Java Driver for Apache Cassandra does not support Guava 20 and 21 yet (see: JAVA-1328).

    However, there is a working PR that has been tested for Guava 16.01, 17.0, 18.0, 19.0, 20.0 and 21.0 and we are targetting version 3.2.0 for this fix.

    I just noticed that the pom.xml from pmml-evaluator you shared shows a supported version range of [14.0, 20.0]:

    <dependency>
      <groupId>com.google.guava</groupId>
      <artifactId>guava</artifactId>
      <version>[14.0, 20.0]</version>
    </dependency>
    

    What you could do is exclude guava as a dependency in org.jpmml, i.e.:

    <dependency>
      <groupId>org.jpmml</groupId>
      <artifactId>pmml-evaluator</artifactId>
      <version>1.3.4</version>
      <exclusions>
        <exclusion>
          <groupId>com.google.guava</groupId>
          <artifactId>guava</artifactId>
        </exclusion>
      </exclusions>
    </dependency>
    

    This should prevent guava 20.0 from being pulled in as a result of resolving dependencies for pmml-evaluator and guava 16.01 would instead be pulled in via transitive dependency of the java driver.