Netflix / astyanax

Cassandra Java Client
Apache License 2.0
1.04k stars 357 forks source link

java.lang.NoSuchMethodError: com.google.common.cache.CacheBuilder.build()Lcom/google/common/cache/Cache; #613

Open steowens opened 8 years ago

steowens commented 8 years ago

Trying to load up an Astyanax context, but I keep getting an error in my stack trace as follows:

Caused by: java.lang.NoSuchMethodError: com.google.common.cache.CacheBuilder.build()Lcom/google/common/cache/Cache;
    at com.netflix.astyanax.thrift.ThriftKeyspaceImpl.<init>(ThriftKeyspaceImpl.java:116)
    at com.netflix.astyanax.thrift.ThriftFamilyFactory.createKeyspace(ThriftFamilyFactory.java:41)
    at com.netflix.astyanax.AstyanaxContext$Builder.buildKeyspace(AstyanaxContext.java:146)
    at com.disney.tss.auth.backend.persistence.CassandraClient.<init>(CassandraClient.java:28)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
    at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:147)
    ... 25 more

I am using Maven to resolve dependencies and I saw that astyanax is using guava 15.0. I tried explicitly setting that dependency and it didn't work. I tried updating my explicit dependency to guava 19.0 and THAT didn't work either. Nothing in my dependencies wants an older guava than 15.0, so I am pretty much blocked from trying out this client because of this. Any ideas or things I might try?

splatch commented 8 years ago

@steowens Try use maven dependency management to force usage of specific version of library in your project and its dependencies.

steowens commented 8 years ago

I am not exactly sure which version to force. After removing everything and plugging in the cassandra-driver-core, I still get very similar errors. I know that you don't use the cassandra-driver-core (or at least I don't think so). But I have tried 15.0, 16.0.1, and 19. All of them pretty much die in the same way but perhaps with slightly different errors. For example the cassandra-driver-core yields the following error in the same class on startup with the 16.0.1 version of guava:

Caused by: java.lang.NoSuchMethodError: com.google.common.cache.CacheBuilder.maximumWeight(J)Lcom/google/common/cache/CacheBuilder;
    at com.datastax.driver.core.CodecRegistry.defaultCacheBuilder(CodecRegistry.java:305)
    at com.datastax.driver.core.CodecRegistry.<init>(CodecRegistry.java:297)
    at com.datastax.driver.core.CodecRegistry.<clinit>(CodecRegistry.java:172)
    at com.datastax.driver.core.Configuration$Builder.build(Configuration.java:276)
    at com.datastax.driver.core.Cluster$Builder.getConfiguration(Cluster.java:1221)
    at com.datastax.driver.core.Cluster.<init>(Cluster.java:116)
    at com.datastax.driver.core.Cluster.buildFrom(Cluster.java:181)
    at com.datastax.driver.core.Cluster$Builder.build(Cluster.java:1238)
    at com.disney.tss.auth.backend.persistence.CassandraClient.<init>(CassandraClient.java:31)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
    at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:147)
    ... 25 more

Not exactly the same but in the very near vicinity of the errors that astyanx yields. I seem to recall ripping guava out of a different project when I started running into bizzare errors. You see, I can see my maven dependencies, I can find the exact method shown in the jar so I really don't understand why this is happening It is very strange indeed. I am going to open up an incident on the guava code base as well since guava CacheBuilder seems to be the implicated party here. I wonder if guava does some hanky panky with the class loaders that confuses things.

Another theory is that somehow the maven tomcat7 plugin is causing something bad to happen. But my WAR has a current version of guava.

pdharish commented 6 years ago

I am seeing similar exception in our product log, though the build went successful. Is there any solution yet for the exception? Caused by: java.lang.NoSuchMethodError: com.google.common.cache.CacheBuilder.build()Lcom/google/common/cache/Cache;

splatch commented 6 years ago

@pdharisin Your classpath contains two or more versions of guava. Depending on order of these you get error or not. Make sure you have just one guava binary available to application.