Hot questions for Handling Error in Guava

Top 10 Java Open Source / Guava / Handling Error

IllegalAccessError to guava's StopWatch from org.apache.hadoop.mapreduce.lib.input.FileInputFormat.listStatus

Question: I'm trying to run small spark application and am getting the following exception:

Exception in thread "main" java.lang.IllegalAccessError: tried to access method<init>()V from class org.apache.hadoop.mapreduce.lib.input.FileInputFormat
    at org.apache.hadoop.mapreduce.lib.input.FileInputFormat.listStatus(
    at org.apache.hadoop.mapreduce.lib.input.CombineFileInputFormat.getSplits(
    at org.apache.spark.rdd.NewHadoopRDD.getPartitions(NewHadoopRDD.scala:95)
    at org.apache.spark.rdd.RDD$$anonfun$partitions$2.apply(RDD.scala:219)
    at org.apache.spark.rdd.RDD$$anonfun$partitions$2.apply(RDD.scala:217)
    at scala.Option.getOrElse(Option.scala:120)

the relevant gradle dependencies section:

compile('org.apache.hadoop:hadoop-mapreduce-client-core:2.6.2') {force = true}
compile('org.apache.hadoop:hadoop-mapreduce-client-app:2.6.2') {force = true}
compile('org.apache.hadoop:hadoop-mapreduce-client-shuffle:2.6.2') {force = true}
compile('') { force = true }

Answer: version 2.6.2 of hadoop:hadoop-mapreduce-client-core can't be used together with guava's new versions (I tried 17.0 - 19.0) since guava's StopWatch constructor can't be accessed (causing above IllegalAccessError)

using hadoop-mapreduce-client-core's latest version - 2.7.2 (in which they don't use guava's StopWatch in the above method, rather they use org.apache.hadoop.util.StopWatch) solved the problem, with two additional dependencies that were required:

compile('org.apache.hadoop:hadoop-mapreduce-client-core:2.7.2') {force = true}

compile('org.apache.hadoop:hadoop-common:2.7.2') {force = true} // required for org.apache.hadoop.util.StopWatch  

compile('commons-io:commons-io:2.4') {force = true} // required for that is used internally

Note: there are two packages: commons-io:commons-io (ours here), and org.apache.commons:commons-io (old one, 2007). make sure to include the correct one.

NoSuchMethodError: conflits on Elastic Search jar

Question: While creating Elasticsearch Client, I'm getting the exception "java.lang.NoSuchMethodError:;" After some lookup, seams like the Guava-18 is being overwrite by an older version at runtime, and Guava-18 only works during compile task.

My Maven configuration is the follow:

                            <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>

How can i force the Guava-18 version at execution time?

Answer: You should try to find where the "old" version of guava is taken from and to exclude it once for all.

Find the dependency:

mvn dependency:tree | grep guava

Exclude it:


Maven "could not parse error message" (Java 7 + Maven 2)

Question: I have a maven-based GWT project that includes Guava. I am running into trouble with Maven trying (and failing) to compile the sources that it finds in guava-gwt*.jar:

could not parse error message:   symbol:   static setCountImpl
  location: class
/home/mark/.m2/repository/com/google/guava/guava-gwt/11.0.1/guava-gwt-11.0.1.jar(com/google/common/collect/ error: cannot find symbol
    return setCountImpl(this, element, count);

I can't figure out why Maven thinks it needs to compile the sources in guava-gwt. Here's what my project looks like:

├── pom.xml
└── src
    ├── main
       └── java
    └── test
        └── java

public class SomeTestFile {
    public void testMethod() {
        Multimap<Integer, String> someMap = ArrayListMultimap.create();
        someMap.put(5, "five");


<?xml version="1.0" encoding="UTF-8"?>
<project xmlns=""








I have already tried the following:

1. Removing the guava dependency (leaving only guava-gwt)

2. Scoping guava-gwt to provided

I'm not sure what else to try. guava-gwt includes sources because GWT will compile it into equivalent Javascript. But I don't want Maven to try to compile these sources.

Answer: The exact pom file along with the test class above compiles fine on my Windows box with maven 3.0.4.

The problem could be with the maven version that you are using. Or there could be other maven goals in the actual pom, which may be causing an issue.

Guava: java.lang.NoClassDefFoundError -

Question: I currently face the problem of java.lang.NoClassDefFoundError: when using guava libraries

I already add guava-12.0.jar into my project as a reference library but I still get the error. May you give some advice on what the problem would be? Thankyou for your help

public class MainActivity extends Activity{

     private BiMap<String,String>  bidiMap; 

    public void onCreate(Bundle savedInstanceState) {

        bidiMap = HashBiMap.create();           

Error Message I get

05-29 18:35:19.737: E/AndroidRuntime(376): FATAL EXCEPTION: main
05-29 18:35:19.737: E/AndroidRuntime(376): java.lang.NoClassDefFoundError:
05-29 18:35:19.737: E/AndroidRuntime(376):  at my.project.MainActivity.onCreate(
05-29 18:35:19.737: E/AndroidRuntime(376):  at

Answer: This error means that the class was available at compile time, but cannot be found during run time. It most commonly happens when your compile time classpath is different from your runtime classpath.

It is very likely that your runtime classpath doesn't contain the guava jar. To verify this, try printing your classpath in your code.

on the command line, you can use: java -cp "path/to/guava.jar" MyMainClass

or alternatively, set the CLASSPATH environment variable to include the jar.

How to remedy error caused by guava: Program type already present:

Question: An AAR library already uses

If an app includes the following in its build.gradle:

api ''

Building the app generates the following error:

Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
> Error while merging dex archives: ...
  Learn how to resolve the issue at
  Program type already present:

If I do not include "api ''", the app can be built, but it has runtime error of java.lang.NoClassDefFoundError when it reaches the point of using the Guava method: Iterables.find

Answer: Since Guava 27.0, ListenableFuture is located in separate artifact, see the announcement. You can try two things (one at a time):

  1. Exclude "listenablefuture" module (group "") and build your project again.
  2. I don't know the AAR specifics, but it could be that 27.0-android doesn't work with AAR, so you should try 27.0.1-android or higher instead.
implementation ''